master
E. Almqvist 3 years ago
parent cb6911dc61
commit 7de25c02d8
  1. 8
      ma5/rsa/brute.rb
  2. 5
      ma5/rsa/rsa.rb
  3. 7
      ma5/rsa/test.rb

@ -1,11 +1,7 @@
#!/usr/bin/ruby -w
#!/usr/bin/ruby
require_relative "rsa.rb"
# pubkey : 7, 143
# msg : 81
# find n = 143 with primes
Primes = File.read("primes.txt").split(",")
# BigPrimes = File.readlines("bigprimes.txt")
print "Modbase target: "
target = gets.chomp.to_i

@ -33,8 +33,6 @@ module RSA
end
@e = enc.sample
@d = RSA.modinv(@e, @phi)
puts "e: #{@e} d: #{@d}"
end
def pubkey
@ -55,7 +53,6 @@ module RSA
c.ord.to_i
end
end
puts "Generated bytes: #{self.raw}"
end
def raw
@ -68,7 +65,7 @@ module RSA
def inspect(endchar="\n")
pattern = "c" * @data.length
return "# \'#{@data.pack(pattern)}\'#{endchar}"
return "\'#{@data.pack(pattern)}\'#{endchar}"
end
def encrypt(pubkey)

@ -1,8 +1,8 @@
#!/usr/bin/ruby -w
#!/usr/bin/ruby
require_relative "rsa"
Primes = File.read("smallprimes.txt").chomp.split(",").map do |pstr|
p = pstr.to_i
pstr.to_i
end
def get_random_primes
@ -40,10 +40,13 @@ print "Message to be encrypted: "
msg = gets.chomp
data = RSA::Data.new(msg)
puts
data.encrypt!(key.pubkey)
puts "Encrypted bytes: #{data.raw}"
puts
data.decrypt!(key.privkey)
puts "Decrypted bytes: #{data.raw}"
puts "Decrypted msg: #{data.inspect}"

Loading…
Cancel
Save