Created
July 4, 2018 18:49
-
-
Save ItsASine/aeadc396626e7e707a664e26e7f63216 to your computer and use it in GitHub Desktop.
Testing out an RSA logic script with super low primes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.setrecursionlimit(100) | |
def eea(stuff, thing): | |
if stuff != 0: | |
(gcd, s, t) = eea(thing % stuff, stuff) | |
return gcd, t - (thing // stuff) * s, s # // is quotient only division | |
else: | |
return thing, 0, 1 | |
def inversemod(number, mod): | |
(gcd, s, t) = eea(number, mod) | |
if gcd == 1: | |
return s % mod | |
else: | |
return None # modular inverse can only be found if numbers are coprime | |
e = 7 | |
p = 11 | |
q = 13 | |
n = p * q | |
phi = (p - 1) * (q - 1) | |
def encrypt(message): | |
return (message ** e) % n | |
d = inversemod(e, phi) | |
def decrypt(cipher): | |
return (cipher ** d) % n | |
print('n: ' + str(n)) | |
print('phi: ' + str(phi)) | |
print('d: ' + str(d)) | |
if e == 7 and p == 11 and q == 13: | |
print(d == 103) | |
print('public: (' + str(e) + ',' + str(n) + ')') | |
print('private: (' + str(d) + ',' + str(n) + ')') |
Author
ItsASine
commented
Jul 4, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment