public static byte[] GetCollision(byte[] source, CustomHasherBase hasher) { byte[] collision = new byte[source.Length]; Array.Copy(source, collision, source.Length); Dictionary <byte, int> counter = new Dictionary <byte, int>(); for (int i = 0; i < collision.Length; ++i) { byte key = (byte)(collision[i] % hasher.Size + 1); if (!counter.ContainsKey(key)) { counter.Add(key, 0); } ++counter[key]; } foreach (byte key in counter.Keys.ToList()) { if (counter[key] % 2 != 0) { --counter[key]; } } for (int i = 0; i < collision.Length; ++i) { byte key = (byte)(collision[i] % hasher.Size + 1); if (counter[key] == 0) { continue; } if (counter[key] % 2 == 0) { collision[i] += (byte)(hasher.Size); } else { collision[i] -= (byte)(hasher.Size); } --counter[key]; } return(collision); }
private static byte[] GetHash(string input, CustomHasherBase hasher) { byte[] data = Encoding.UTF8.GetBytes(input); return(hasher.ComputeHash(data)); }