Protip: Try to reverse the XORed output by using key. Turning Symmetric Encryption Secure(Level 5): If you have come so far, congratulations. Now as you know by now that symmetric Encryption is not secure due to the risk of the key being stolen well, there exists a hybrid solution. What if we can securely send the key through asymmetric encryption and use fast symmetric encryption to send the messages?
Welcome to the world of DH or Diffie-Hellman Key Exchange. Ever wondered when you’re trying to log into ssh why does the word Diffie-Hellman is tossed around?
Why is Diffie Helman?
Diffie Hellman (DH) does not encrypt data. Its main purpose is to create a secure session so that symmetric data can travel down it. DH creates the keys used in the Internet Key Exchange (IKE); it uses UDP port 500 to set up the secure session for the L2TP/IPSec VPN. Once the secure tunnel has been created, then the symmetric encrypted data flows down the tunnel.
This is genius but wait you also need to know internal workings, welcome more maths:
How does it work? For completing a secure tunnel, the algorithm assumes a prime number, for example, q and select its primitive root, so lets choose alpha as the primitive root of q. The condition being that alpha has to be less than q. What exactly is a primitive root? (denoting alpha as a)
Well alpha is a primitive root of q if:
a mod q, a²mod q, a³ mod q , a⁴ mod q …….a^q-1 mod q = 1,2,3…q-1 Now lets the generate the public and private key of USER A.
Now assuming X is the private key, we have to make sure that XaNow the public is denoted by Y. Thus we use the Formula to get the public key= Ya = alpha^Xa mod q.THUS {Xa,Ya}
And we have both, pretty simple if you have a good understanding of maths.
Now the same process for User B.
Now, sender, each group has 3 things Xa,Yb, and prime number q.
We simply we the formula for A k =(YB)^xA Mod q
Same for user B.
Simple Formula
Now you know how Diffie hellman key exchange works!
Cryptography is vast and cannot be summed up into one post or even a book. I tried to explain and cover almost all aspects. Next, we can look over some cryptographic mathematical attacks and also break down some use cases. If you want go to liveoverflow and watch the google hacking cup challenge and learn about ECB block cipher attacks. Here’s a simple breakdown of coppersmith:https://acmccs.github.io/papers/p1631-nemecA.pdf Thank you all for reading. I wrote this in one sitting to might have minor mistakes though im a perfectionist. Keep Learning:)
As Aristotle once said and i quote: