one-file-projects/rsa.py

17 lines
345 B
Python
Raw Normal View History

def e(m,e,n):
f = 1
print("%d ^ %d mod %d" %(m,e,n))
while e != 1:
print("= %d ^ %d * %d mod %d" % (m,e,f,n))
if e % 2 == 1:
f *= m
e -= 1
f = f % n
m = (m * m) % n
e /= 2
print("= %d * %d mod %d" % (m,f,n))
c = (m*f) % n
print("= %d" % c)
e(20,13,33)