Skip to content

Instantly share code, notes, and snippets.

@aburgd
Created December 1, 2015 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aburgd/79c03a1534633882ba58 to your computer and use it in GitHub Desktop.
Save aburgd/79c03a1534633882ba58 to your computer and use it in GitHub Desktop.
publicKey class method
class Diffie
p defined?(Diffie)
def publicKey(base, modPrime, aSecret)
@publicKey = 0
# puts "Enter your shared prime (g): "
# base = Integer(gets.chomp)
# puts "Enter your second prime (p): "
# modPrime = Integer(gets.chomp)
# puts "Enter your secret prime (a): "
# aSecret = Integer(gets.chomp)
@publicKey = base ** aSecret % modPrime
print "Share this with your contact: " + publicKey
end
end
$ ruby DHKE.rb
"constant"
Are you computing the public key or the shared secret?
public key
"constant"
Enter your shared prime (g):
7
Enter your second prime (p):
5
Enter your secret prime (a):
2
DHKE.rb:17:in `<main>': undefined method `publicKey' for nil:NilClass (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment