From 7e6191bede6beb450435c00c41e77ad5b0114765 Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Tue, 15 Aug 2023 09:44:56 -0400 Subject: [PATCH] Create 02_Diffie_Hellman_Key_Exchange.md --- .../02_Diffie_Hellman_Key_Exchange.md | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 crypto/challenges/02_Diffie_Hellman_Key_Exchange.md diff --git a/crypto/challenges/02_Diffie_Hellman_Key_Exchange.md b/crypto/challenges/02_Diffie_Hellman_Key_Exchange.md new file mode 100644 index 0000000..e5bcb33 --- /dev/null +++ b/crypto/challenges/02_Diffie_Hellman_Key_Exchange.md @@ -0,0 +1,64 @@ +# Challenge 2: Simple RSA Encryption + +**Challenge Text:** +``` +n = 3233, e = 17, Encrypted message: [2201, 2332, 1452] +``` + +**Instructions:** +1. Factorize the value of \( n \) into two prime numbers, \( p \) and \( q \). +2. Compute the private key \( d \) using the Extended Euclidean Algorithm. +3. Decrypt the message using the computed private key. + +### Answer: + +Here are the detailed solutions for each step: + +**Step 1:** Factorize \( n = 3233 \) into two prime numbers: + \( p = 61 \), \( q = 53 \) + +**Step 2:** Compute the Euler's Totient function \( \phi(n) \): + \( \phi(n) = (p-1)(q-1) = 3120 \) + +Compute the private key \( d \) such that: + \( de \equiv 1 \mod \phi(n) \) + +Using Extended Euclidean Algorithm, we can find: + \( d = 2753 \) + +**Step 3:** Decrypt the message using the private key: + Decrypted message: "HEY" + +Here's a code snippet in Python to perform the entire decryption: + +```python +def egcd(a, b): + if a == 0: + return (b, 0, 1) + else: + g, x, y = egcd(b % a, a) + return (g, y - (b // a) * x, x) + +def modinv(a, m): + g, x, y = egcd(a, m) + if g != 1: + raise Exception('Modular inverse does not exist') + else: + return x % m + +def decrypt_rsa(ciphertext, n, e): + p, q = 61, 53 # Factored values + phi = (p-1)*(q-1) + d = modinv(e, phi) + plaintext = [str(pow(c, d, n)) for c in ciphertext] + return ''.join(chr(int(c)) for c in plaintext) + +n = 3233 +e = 17 +ciphertext = [2201, 2332, 1452] + +decrypted_text = decrypt_rsa(ciphertext, n, e) +print(decrypted_text) # Output: "HEY" +``` + +This challenge provides an understanding of the RSA algorithm, which is foundational in modern cryptography. It covers important concepts like prime factorization, modular arithmetic, and key derivation.