From 61f0f65ea95009f6fbfa51ec8c5956f71c7447b2 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 28 Feb 2022 10:28:13 +0100 Subject: [PATCH] Stuff --- ma5/rsa/brute.rb | 20 +++++++++++++++----- ma5/rsa/rsa.rb | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ma5/rsa/brute.rb b/ma5/rsa/brute.rb index 32fda27..4630cce 100755 --- a/ma5/rsa/brute.rb +++ b/ma5/rsa/brute.rb @@ -1,10 +1,12 @@ #!/usr/bin/ruby +require_relative "rsa.rb" + Primes = File.read("primes.txt").split(",") # BigPrimes = File.readlines("bigprimes.txt") -print "Modbase target: " -target = gets.chomp.to_i +#print "Modbase target: " +#target = gets.chomp.to_i def bruteforce(target) Primes.each do |p| @@ -19,6 +21,14 @@ def bruteforce(target) end end -p1, p2 = bruteforce(target) -puts "Found primes:" -puts p1, p2 +def gen_key(p1, p2, e) + puts "Generating key pair..." + n = p1 * p2 + phi = (p1-1)*(p2-1) + + d = RSA.modinv(e, phi) + return e, n, d +end +#p1, p2 = bruteforce(target) +#puts "Found primes:" +#puts p1, p2 diff --git a/ma5/rsa/rsa.rb b/ma5/rsa/rsa.rb index 04136d1..9781499 100644 --- a/ma5/rsa/rsa.rb +++ b/ma5/rsa/rsa.rb @@ -18,6 +18,7 @@ module RSA end class Key + attr_accessor :e, :d, :n def initialize(p1, p2) puts "Generating key pair..." @n = p1 * p2 @@ -36,7 +37,7 @@ module RSA end def inspect - "n=#{@n}" + "n=#{@n} e=#{@e} d=#{@d}" end def pubkey