mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2024-12-18 10:56:09 +00:00
Create 05_Implement_Diffie_Hellman_Key_Exchange.md
This commit is contained in:
parent
57119589e9
commit
0cd4c91d5b
@ -0,0 +1,42 @@
|
||||
# Challenge 5: Implement Diffie-Hellman Key Exchange
|
||||
|
||||
**Level:** Intermediate
|
||||
|
||||
**Description:**
|
||||
Simulate the Diffie-Hellman key exchange algorithm to securely share a symmetric key between two parties.
|
||||
|
||||
**Challenge Text:**
|
||||
```
|
||||
Given prime p = 23, base g = 5
|
||||
Party A's private key: 6
|
||||
Party B's private key: 15
|
||||
```
|
||||
|
||||
**Instructions:**
|
||||
1. Compute Party A's and Party B's public keys.
|
||||
2. Compute the shared secret key for both parties.
|
||||
3. Validate that both parties have the same shared secret key.
|
||||
|
||||
|
||||
**Answer:**
|
||||
Shared secret key: 2
|
||||
|
||||
**Code:**
|
||||
```python
|
||||
p = 23
|
||||
g = 5
|
||||
a_private = 6
|
||||
b_private = 15
|
||||
|
||||
# Compute public keys
|
||||
A_public = (g ** a_private) % p
|
||||
B_public = (g ** b_private) % p
|
||||
|
||||
# Compute shared secret key
|
||||
shared_secret_A = (B_public ** a_private) % p
|
||||
shared_secret_B = (A_public ** b_private) % p
|
||||
|
||||
print("Shared secret key (Party A):", shared_secret_A)
|
||||
print("Shared secret key (Party B):", shared_secret_B)
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user