-
-
Save anonymous/02a8647f6886fff51fc1 to your computer and use it in GitHub Desktop.
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
# 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