Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Security.Cryptography;
- using System.Collections;
- using System.Linq;
- using System.Runtime.Remoting.Metadata.W3cXsd2001;
- namespace abloop
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<byte[], string> collisionTable = new Dictionary<byte[], string>();
- SoapHexBinary hexString = new SoapHexBinary();
- Random pseudoRNG = new Random();
- SHA256 hashSha = new SHA256Cng();
- for (int i = 0; i < 39506988; i++)
- //For a 50 bit hash, this number gives us a ~50% chance for collision.
- {
- byte[] byteContainer = new byte[8];
- byte[] fiftyBitHash = new byte[7];
- pseudoRNG.NextBytes(byteContainer);
- //Generate prng number to hash
- byte[] hashedBYTES = hashSha.ComputeHash(byteContainer);
- //Use SHA256 to hash prng number
- fiftyBitHash[0] = (byte)(((int)hashedBYTES[25]) << 6);
- fiftyBitHash[0] = (byte)((int)fiftyBitHash[0] >> 6);
- fiftyBitHash[1] = hashedBYTES[26];
- fiftyBitHash[2] = hashedBYTES[27];
- fiftyBitHash[3] = hashedBYTES[28];
- fiftyBitHash[4] = hashedBYTES[29];
- fiftyBitHash[5] = hashedBYTES[30];
- fiftyBitHash[6] = hashedBYTES[31];
- //Get the right 50 bits of the hash
- hexString.Value = fiftyBitHash;
- collisionTable.Add(byteContainer, hexString.ToString());
- //Add both to the dictionary
- }
- var k = collisionTable.GroupBy(p => p.Value).Where(p => p.Count() > 1).Select(p => p).First();
- //Find collisions using LINQ magic
- Console.WriteLine(k.Count());
- foreach (var item in k)
- {
- Console.WriteLine(item.Value);
- var xud = new SoapHexBinary(item.Key);
- Console.WriteLine(xud.ToString());
- //Print the lsb(50) hash and the bytes used for the collision
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment