1
$\begingroup$

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?

$\endgroup$

2 Answers 2

2
$\begingroup$

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/

$\endgroup$
4
  • $\begingroup$ are there anyway to replace this using Q#? $\endgroup$ Mar 24, 2020 at 4:38
  • $\begingroup$ Can you please help us understand why do you want to run this *kind of * code on Quantum Simulator? Quantum Simulator / Device is not meant to run such code. There is no "lift and shift" here. You want to explore tasks which are considered intractable ...for traditional computing - such tasks should be prepared for Quantum Computing. $\endgroup$
    – abRao
    Mar 24, 2020 at 17:39
  • $\begingroup$ i try to see the performance of azure quantum & Q# is as fast as they said, i don't have much knowledge about cryptography or breaking password so this is the easiest code i can come up with $\endgroup$ Mar 25, 2020 at 2:48
  • $\begingroup$ The Quantum Computers (of today called NISQ) and Quantum Simulator cant do anything faster than traditional computer. Please read this paper - quantamagazine.org/… - it explains how Google devised an algorithm on quantum computer that outperformed traditional computer. I suggest you please consider reading the links above to understand where we as an industry are. $\endgroup$
    – abRao
    Mar 25, 2020 at 3:23
0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ I try to see the performance of Microsoft quantum is as powerful they said, i can make more complicated method(Sha256, mnemonic, ...). As i see their Grover's search example, it can only search existed list, not much to implement brute force, i'm more interested in birthday attack & collision attack $\endgroup$ Mar 25, 2020 at 2:53
  • $\begingroup$ There exist other examples of using Grover's search, breaking hash is closer to solving SAT problem (github.com/microsoft/QuantumKatas/tree/master/… followed by github.com/microsoft/QuantumKatas/tree/master/tutorials/…) - you start with a mathematical description of the problem, and search for a solution that satisfies that description. It still doesn't give you a lot of benefit, as the linked answer explains. $\endgroup$ Mar 25, 2020 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.