1

I have a code like this

public string CalculateMD5Hash(string input)
{

    MD5 md5 = System.Security.Cryptography.MD5.Create();
    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
    byte[] hash = md5.ComputeHash(inputBytes); 

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hash.Length; i++)
    {
        sb.Append(hash[i].ToString("X2"));
    }
    return sb.ToString();
}

public bool checkHash(){
 List<string> charset = new List<string>{"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
 foreach(var a in charset)
 {
     foreach(var b in charset){
         foreach(var c in charset){
             foreach(var d in charset){
                  foreach(var e in charset)
                  {
                    string result = a+b+c+d+e;
                    if(CalculateMD5Hash(result).StartWiths("9A4F2E9567F170C5"))
                      return true;
                  }              
             }           
         }
     }   
 }
 return false;
}

Is this possible to bring this into Q# & run them on Azure Quantum using some of the Q# quantum method?

2 Answers2

2

You cannot deploy C# to Q# Azure platform; Q# Azure platform executes a Quantum Simulator. The C# host program calls Q# operations to be executed on the Quantum Simulator - the code you have here will execute on a traditional computing processor.

Please read this link - https://docs.microsoft.com/en-us/quantum/quickstart

And this link more about the Azure Quantum - https://azure.microsoft.com/en-us/services/quantum/

Please read this article to set the right expectation https://www.scientificamerican.com/article/how-close-are-we-really-to-building-a-quantum-computer/

abhi-rao
  • 238
  • 1
  • 7
0

MD5 hashes are not that hard to crack classically, you probably don't need a quantum computer to do that (for your hash prefix, the pre-image is 2435435 with full hash 9a4f2e9567f170c5685b57d8a6c0af6f).

In general, one can use Grover's search algorithm for breaking hash functions; you'd have to implement the hash calculation in a reversible manner (so that it can be executed on a quantum computer) and try to invert function "f(x) = 1 if hash(x) = your hash, and 0 otherwise".

You can see this excellent answer for an overview of papers that analyze applying Grover's search to breaking various hashes, and a note on practicality of such attacks.

Mariia Mykhailova
  • 9,285
  • 1
  • 13
  • 40