require 'rational'こんな感じなんかなぁ。
def n_fact(p, q)
$n = p * q
print "N = ", $n, "\n"
$l = (p-1).lcm(q-1)
print "L = ", $l, "\n"
$e = 1
continue_e = true
while continue_e do
$e += 1
if $e.gcd($l) == 1 then
print "E = ", $e, "\n"
continue_e = false
end
end
$d = 1
continue_d = true
while continue_d do
$d += 1
if $e * $d % $l == 1 then
print "D = ", $d, "\n"
continue_d = false
end
end
end
#Encrypt(plain text(ascii))
def e(p)
p p**$e % $n
end
#Decode(code(num))
def d(c)
p c**$d % $n
end
n_fact()に素数のペア渡してあげたら暗号化と復号に要る数を出してくれるみたいです
なんか間違っとるとこあったら教えてください...
もちろん実用性は皆無です