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/

abRao
  • 248
  • 1
  • 6
  • are there anyway to replace this using Q#? – Tran Duc Toan Mar 24 '20 at 04:38
  • 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. – abRao Mar 24 '20 at 17:39
  • 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 – Tran Duc Toan Mar 25 '20 at 02:48
  • The Quantum Computers (of today called NISQ) and Quantum Simulator cant do anything faster than traditional computer. Please read this paper - https://www.quantamagazine.org/john-preskill-explains-quantum-supremacy-20191002/ - 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. – abRao Mar 25 '20 at 03:23
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,010
  • 1
  • 12
  • 39
  • 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 – Tran Duc Toan Mar 25 '20 at 02:53
  • There exist other examples of using Grover's search, breaking hash is closer to solving SAT problem (https://github.com/microsoft/QuantumKatas/tree/master/SolveSATWithGrover followed by https://github.com/microsoft/QuantumKatas/tree/master/tutorials/ExploringGroversAlgorithm) - 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. – Mariia Mykhailova Mar 25 '20 at 03:10