diff options
-rw-r--r-- | final/rsa-decrypt.py | 8 | ||||
-rw-r--r-- | final/rsa-encrypt.py | 9 |
2 files changed, 9 insertions, 8 deletions
diff --git a/final/rsa-decrypt.py b/final/rsa-decrypt.py index d05b351..39a2720 100644 --- a/final/rsa-decrypt.py +++ b/final/rsa-decrypt.py @@ -1,9 +1,9 @@ -encrypted = [405, 35, 133, 371, 435, 279] # Directly from demo output of encrypted -p = 29 -q = 17 +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 = 3 +e = int(input('e: ')) # Calculate d such that ed == 1 mod tot d = 1 # Guess diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py index de9ba1e..a15fe9d 100644 --- a/final/rsa-encrypt.py +++ b/final/rsa-encrypt.py @@ -1,10 +1,12 @@ -p = 29 +'''p = 29 q = 17 n = p*q tot = (p-1)*(q-1) -e = 3 # Many present strictly for convenience's sake +e = 3 # Many present strictly for convenience's sake''' +n = int(input('n: ')) +e = int(input('e (make sure it\'s relatively prime to p-1 and q-1): ')) -message = 'abcdef' +message = input('message:\n') messagenum = 0 for char in message: messagenum += ord(char) @@ -14,7 +16,6 @@ messageblocks = [] while messagenum > 0: messageblocks.append(messagenum%n) messagenum = (messagenum-messagenum%n)//n -print(messageblocks) def encrypt_block(blk): return (blk ** e) % n |