Old high school files. Lessson notes/codes/projects etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hsf/ma5/rsa/test.rb

28 lines
466 B

3 years ago
#!/usr/bin/ruby -w
require_relative "rsa"
Primes = File.read("primes.txt").chomp.split(",").map do |pstr|
pstr.to_i
end
puts "Fetching random primes..."
p1, p2 = Primes.sample, Primes.sample
p1, p2 = 11, 13
puts "p1=#{p1}, p2=#{p2}"
puts
key = RSA::Key.new(p1, p2)
print "Message to be encrypted: "
msg = gets.chomp
data = RSA::Data.new(msg)
data.encrypt!(key.pubkey)
puts "Encrypted bytes: #{data.raw}"
data.decrypt!(key.privkey)
puts data.raw
p data.data