diff options
author | holden watson <holdenew@gmail.com> | 2019-11-11 23:41:01 -0500 |
---|---|---|
committer | holden watson <holdenew@gmail.com> | 2019-11-11 23:41:01 -0500 |
commit | db732bd93ffc688e16a0d9e0eb2e321315fd4621 (patch) | |
tree | 926c4c0d654106bc1d09afd2e0541943addc4743 /final/rsa-decrypt.py | |
parent | e60926a2bfa1fee117c7d2175a7963b02801c16f (diff) | |
parent | c8e69070fbd09863b563730630e7f60fe44d7dac (diff) |
Merge branch 'master' of https://github.com/feynmansfedora/appcomb-proj
Diffstat (limited to 'final/rsa-decrypt.py')
-rw-r--r-- | final/rsa-decrypt.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/final/rsa-decrypt.py b/final/rsa-decrypt.py new file mode 100644 index 0000000..39a2720 --- /dev/null +++ b/final/rsa-decrypt.py @@ -0,0 +1,29 @@ +encrypted = [340, 316, 145, 278, 250, 435, 321, 109, 115, 490, 156, 212, 122, 288, 287, 164, 225] # Directly from demo output of encrypted +p = int(input('prime 1: ')) +q = int(input('prime 2: ')) +n = p*q +tot = (p-1)*(q-1) +e = int(input('e: ')) + +# Calculate d such that ed == 1 mod tot +d = 1 # Guess +while (e*d % tot != 1): + d += 1 +# Algorithm is currently extremely dumb + +def decrypt_block(blk): + return blk**d % n + +decrypted = [decrypt_block(block) for block in encrypted] + +messagenum = 0 +for blockind in range(len(decrypted)): + block = decrypted[blockind] + messagenum += block * n ** blockind + +message = '' +while messagenum > 0: + message = chr(messagenum%128) + message + messagenum = (messagenum-messagenum%128)//128 + +print(message) |