-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
822a531
commit 03f194b
Showing
7 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Instructions | ||
|
||
Diffie-Hellman key exchange. | ||
|
||
Alice and Bob use Diffie-Hellman key exchange to share secrets. | ||
They start with prime numbers, pick private keys, generate and share public keys, and then generate a shared secret key. | ||
|
||
## Step 0 | ||
|
||
The test program supplies prime numbers p and g. | ||
|
||
## Step 1 | ||
|
||
Alice picks a private key, a, greater than 1 and less than p. | ||
Bob does the same to pick a private key b. | ||
|
||
## Step 2 | ||
|
||
Alice calculates a public key A. | ||
|
||
A = gᵃ mod p | ||
|
||
Using the same p and g, Bob similarly calculates a public key B from his private key b. | ||
|
||
## Step 3 | ||
|
||
Alice and Bob exchange public keys. | ||
Alice calculates secret key s. | ||
|
||
s = Bᵃ mod p | ||
|
||
Bob calculates | ||
|
||
s = Aᵇ mod p | ||
|
||
The calculations produce the same result! | ||
Alice and Bob now share secret s. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"erikschierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"diffie-hellman.ua" | ||
], | ||
"test": [ | ||
"tests.ua" | ||
], | ||
"example": [ | ||
".meta/example.ua" | ||
] | ||
}, | ||
"blurb": "Diffie-Hellman key exchange.", | ||
"source": "Wikipedia, 1024 bit key from www.cryptopp.com/wiki.", | ||
"source_url": "https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PrivateKey ← ⍜(-2|⌊×)⊙⚂ | ||
PublicKey ← |3 ⊙⋅⋅(⍤ "Please implement PublicKey" 0) | ||
Secret ← |3 ⊙⋅⋅(⍤ "Please implement PublicKey" 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[1b97bf38-4307-418e-bfd2-446ffc77588d] | ||
description = "private key is greater than 1 and less than p" | ||
|
||
[68b2a5f7-7755-44c3-97b2-d28d21f014a9] | ||
description = "private key is random" | ||
|
||
[b4161d8e-53a1-4241-ae8f-48cc86527f22] | ||
description = "can calculate public key using private key" | ||
|
||
[0d25f8d7-4897-4338-a033-2d3d7a9af688] | ||
description = "can calculate public key when given a different private key" | ||
|
||
[cd02ad45-3f52-4510-99cc-5161dad948a8] | ||
description = "can calculate secret using other party's public key" | ||
|
||
[17f13c61-a111-4075-9a1f-c2d4636dfa60] | ||
description = "key exchange" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Generate a private key | ||
# Key ? PrimeP | ||
PrivateKey ← |1 ⊙(⍤"Please implement PrivateKey" 0) | ||
|
||
# Calculate the public key | ||
# PublicKey ? primeP primeG privateKey | ||
PublicKey ← |3 ⊙⋅⋅(⍤ "Please implement PublicKey" 0) | ||
|
||
# Calculate the secret | ||
# Secret ? PrimeP PublicKey PrivateKey = failwith "You need to implement this function." | ||
Secret ← |3 ⊙⋅⋅(⍤ "Please implement PublicKey" 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
~ "diffie-hellman.ua" ~ PrivateKey PublicKey Secret | ||
|
||
# Private key is greater than 1 and less than p | ||
P ← 7919 | ||
⍤⤙≍ 1 /××⊃(≥2|<P) [⍥(PrivateKey P) 1000] | ||
|
||
# Private key is random | ||
P ← 7919 | ||
⍤⤙≍ 1 >100 ⧻◴ [⍥(PrivateKey P) 1000] | ||
|
||
# # Can calculate public key using private key | ||
# p ← 23 | ||
# g ← 5 | ||
# privateKey ← 6 | ||
# ⍤⤙≍ 8 publicKey p g privateKey | ||
|
||
# # Can calculate public key when given a different private key | ||
# p ← 23 | ||
# g ← 5 | ||
# privateKey ← 15 | ||
# ⍤⤙≍ 19 publicKey p g privateKey | ||
|
||
# # Can calculate secret using other party's public key | ||
# p ← 23 | ||
# theirPublicKey ← 19 | ||
# myPrivateKey ← 6 | ||
# ⍤⤙≍ 2 secret p theirPublicKey myPrivateKey | ||
|
||
# # Key exchange | ||
# p ← 23 | ||
# g ← 5 | ||
# alicePrivateKey ← privateKey p | ||
# alicePublicKey ← publicKey p g alicePrivateKey | ||
# bobPrivateKey ← privateKey p | ||
# bobPublicKey ← publicKey p g bobPrivateKey | ||
# secretA ← secret p bobPublicKey alicePrivateKey | ||
# secretB ← secret p alicePublicKey bobPrivateKey | ||
# ⍤⤙≍ secretB secretA |