I am trying to generate three distinct strings, A, B, and C, such that their hash values are all equal using the default hash function provided by the programming language. Specifically, I need to ensure that A is not equal to B, B is not equal to C, and A is not equal to C.
I have tried several approaches but haven't been successful in finding a solution yet. I am seeking assistance to implement a method or algorithm that can fulfill these requirements. It's crucial that the hash values of all three strings are the same.
Here is my implementation, however, it is still incomplete because I have a collision with the first two strings but not with the third one.
var dictionary = new Dictionary<int, string>();
int collusionCounter = 0, stringCounter = 0;
string myString;
int hash = 0;
List<string> myList = new List<string>();
while (true)
{
stringCounter++;
myString = stringCounter.ToString();
try
{
hash = myString.GetHashCode();
dictionary.Add(hash, myString);
}
catch (Exception)
{
if (dictionary.ContainsKey(hash))
{
myList.Add(myString);
collusionCounter++;
if (collusionCounter == 2)
{
break;
}
}
continue;
}
}
var A = myList[0];
var B = myList[1];
var C = dictionary[hash];
Console.WriteLine($"{A.GetHashCode()} {B.GetHashCode()} {C.GetHashCode()}");
And hier is a result of implementation :
374545419 1954295680 1954295680
I would appreciate any guidance or insights on how to achieve this task effectively. Thank you!