Update rsatest.py

This commit is contained in:
Andy 2014-09-11 17:59:58 +02:00
parent a543dd2a84
commit 70c706f0c2

View File

@ -84,7 +84,8 @@ print
print "2. computing n = pq ..."
n = p * q
print "n = p * q =", bcolors.DRED, p, bcolors.ENDC, "*", bcolors.DRED, q, bcolors.ENDC, "=", bcolors.BLUE, n, bcolors.ENDC
print "n = p * q =", bcolors.DRED, p, bcolors.ENDC, "*", bcolors.DRED, q, bcolors.ENDC, "=", \
bcolors.BLUE, n, bcolors.ENDC
print
@ -99,7 +100,9 @@ print
# 4. Choose an integer e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1; i.e., e and φ(n) are coprime.
print "4. looking for an integer e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1; i.e., e and φ(n) are coprime ..."
print "\nSetting e = 2^16+1 (65537) as per recommendation in\nDan Boneh's Twenty Years of Attacks on the RSA Cryptosystem - http://crypto.stanford.edu/~dabo/pubs/papers/RSA-survey.pdf\n"
print "\nSetting e = 2^16+1 (65537) as per recommendation in\n"+ \
"Dan Boneh's Twenty Years of Attacks on the RSA Cryptosystem - "+ \
"http://crypto.stanford.edu/~dabo/pubs/papers/RSA-survey.pdf\n"
#e_gcd = 2
# TOFIX: add smth like --> while (e_gcd != 1) and (e > 3): as e should be > than 3
#while e_gcd != 1:
@ -155,7 +158,8 @@ cstr = ""
mstr = raw_input("Enter your message m: ")
for m in [elem.encode("hex") for elem in mstr]:
print ":: encrypting ", bcolors.YELLOW, '"'+chr(int(m, 16))+'"', \
int(m, 16), bcolors.ENDC, " >>>", bcolors.YELLOW, int(m, 16), bcolors.ENDC, "^", bcolors.CYAN, e, bcolors.ENDC, \
int(m, 16), bcolors.ENDC, " >>>", bcolors.YELLOW, int(m, 16), \
bcolors.ENDC, "^", bcolors.CYAN, e, bcolors.ENDC, \
"( mod", bcolors.BLUE, n, bcolors.ENDC, ")", ">>> ",
c = ( int(m, 16) ** e ) % n
print bcolors.PURPLE, c, bcolors.ENDC