Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created December 1, 2015 00:26
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 anonymous/02a8647f6886fff51fc1 to your computer and use it in GitHub Desktop.
Save anonymous/02a8647f6886fff51fc1 to your computer and use it in GitHub Desktop.
# Pastebin miD0pYiy
Diffie = nil
puts "Are you computing the public key or the shared secret?"
answer = gets.chomp
# beginning of if..else
if answer.downcase.eql? "public key" then
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)
puts "Share this with your contact: " + Diffie.publicKey(base, modPrime, aSecret)
elsif answer.downcase.eql? "shared secret" then
puts "Enter the shared secret from your contact (A): "
publicKey = Integer(gets.chomp)
puts "Enter your second prime (p) :"
modPrime = Integer(gets.chomp)
puts "Enter your secret prime (a): "
aSecret = Integer(gets.chomp)
puts "Compare this with your contact: " + Diffie.shareSecret(publicKey, modPrime, aSecret)
else
puts nil
end
# beginning of dhke class
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
def shareSecret(publicKey, modPrime, aSecret)
@shareSecret = 0
# puts "Enter the shared secret from your contact (A): "
# publicKey = Integer(gets.chomp)
# puts "Enter your second prime (p) :"
# modPrime = Integer(get.chomp)
# puts "Enter your secret prime (a): "
# aSecret = Integer(gets.chomp)
@shareSecret = publicKey ** aSecret % modPrime
print "Compare this with your contact: " + shareSecret
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment