diff options
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..d05b351 --- /dev/null +++ b/final/rsa-decrypt.py @@ -0,0 +1,29 @@ +encrypted = [405, 35, 133, 371, 435, 279] # Directly from demo output of encrypted +p = 29 +q = 17 +n = p*q +tot = (p-1)*(q-1) +e = 3 + +# 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) |