Ребятушки, хочу одну утилитку написать, учусь кодингу заодно на практике, требуется запилить вход на биржу Btc-e.com.
Язык C#.
У сайта есть защита при логине, от перебора наверное. Отправляешь логин и пароль, он тебе в ответ криптографическую задачку вида:
{"success":1, "data":{"PoW":1,"work":{"target":3.1153781151209e+34,"data":"V8C55QPU0G6B768DSWZMWOD5OCJRXKYTV354KWF05K8HRAZDICFY6GGSFBME59C2"}}}
Для браузера есть код, который задачку решает:
function getPoW(a,b){var c=0;do hash=eval("(0x"+login_md5(md5(md5(b+c)))+")"),++c;while(hash>=a);return c}
function login_md5(a){d1=a.substr(0,16);d2=a.substr(16,16);return d2+d1}
/*В качестве a, b значений для функции getPoW используются значения target и data из задачи
*/
Пишу на шарпе так, но считает почему-то неправильно:
public int Get_PoW(string target, string data)
{
int nonce = 0;
target = target.Replace(",", ".");
BigInteger number=1, y = 0;
//func(md5(md5(data+nonce)
MD5 md5 = new MD5CryptoServiceProvider();
while (number > y)
{
byte[] checkSum = md5.ComputeHash(md5.ComputeHash(Encoding.UTF8.GetBytes(data+nonce.ToString())));
string result = BitConverter.ToString(checkSum).Replace("-", String.Empty);
string d1 = result.Substring(0, 16);
string d2 = result.Substring(16, 16);
string hash = d2 + d1;
/*
If value is a hexadecimal string, the TryParse(String, NumberStyles, IFormatProvider, BigInteger)
method interprets value as a negative number stored by using two's complement representation if its
first two hexadecimal digits are greater than or equal to 0x80. In other words, the method interprets
the highest-order bit of the first byte in value as the sign bit. To make sure that a hexadecimal string
is correctly interpreted as a positive number, the first digit in value must have a value of zero.
For example, the method interprets 0x80 as a negative value, but it interprets either 0x080 or 0x0080 as
a positive value.
*/
if (BigInteger.Parse(hash[0].ToString(), NumberStyles.HexNumber) >= 8)
hash = "0" + hash;
number = BigInteger.Parse(hash, NumberStyles.HexNumber);
string number_s = number.ToString();
y = BigInteger.Parse(target, NumberStyles.Float | NumberStyles.AllowExponent, CultureInfo.InvariantCulture);
nonce++;
}
return nonce;
}
Подскажите советом, весь мозг уже сломал