因此,對於某個任務,我被要求在2個隨機的64字節序列之間找到對SHA256
摘要的前n位(n將是4,8 ......)的衝突,即在哈希中查找衝突
SHA256Managed hashstring = new SHA256Managed();
byte[] hash_1 = hashstring.ComputeHash(a);
...
我計算了哈希值的字符串值,
string hashString = string.Empty;
foreach (byte x in hash)
{
hashString += String.Format("{0:x2}", x);
}
return hashString;
我使用字符串匹配功能,第一提取物,說的第8位:
string first8Char_hash1 = new string(hashDisplay(hash_1).Take(8).ToArray());
檢查,如果先說,8位匹配與否,即
if (first8Char_hash1.Equals(first8Char_hash2))
{
//Do something
}
現在,如果我這樣做,說的第4位,我覺得中說碰撞的平均12000次迭代,但是,對於第8位,以及我無法連1之後找到了碰撞, 00,00嘗試。
有什麼問題? 謝謝。
您正在通過將字節轉換爲可迭代來比較字節,然後將其轉換爲數組,然後將其轉換爲字符串;你能想出一個更好的方法來比較字節的平等嗎? –
「直到程序崩潰」出現什麼錯誤? 'OutOfMemoryException'?另外,我不會使用LINQ並調用'Take(8)',然後調用'string.Equals()',但只要使用標準的'for'循環,並且只要一個位不匹配。 –
你已經混淆了字節的位。字節是八位。 –