aboutsummaryrefslogtreecommitdiff
path: root/final/rsa-encrypt.py
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-11-12 10:28:35 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-11-12 10:28:35 -0500
commit8eb41720f151d20f13d7316d30cd8a02c8664e42 (patch)
tree29c02d7e9473f21e7da7da6674971a5f8026399f /final/rsa-encrypt.py
parentfd2de4e488e01fd84d877ceabbd9f0f984d93174 (diff)
allowed user input and base64 intermediary for rsa encrypt/decrypt
Diffstat (limited to 'final/rsa-encrypt.py')
-rw-r--r--final/rsa-encrypt.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py
index a15fe9d..aa52509 100644
--- a/final/rsa-encrypt.py
+++ b/final/rsa-encrypt.py
@@ -1,24 +1,15 @@
-'''p = 29
-q = 17
-n = p*q
-tot = (p-1)*(q-1)
-e = 3 # Many present strictly for convenience's sake'''
+import rsautils as ru
+
n = int(input('n: '))
e = int(input('e (make sure it\'s relatively prime to p-1 and q-1): '))
message = input('message:\n')
messagenum = 0
-for char in message:
- messagenum += ord(char)
- messagenum *= 128 # Assuming ASCII only characters
-
-messageblocks = []
-while messagenum > 0:
- messageblocks.append(messagenum%n)
- messagenum = (messagenum-messagenum%n)//n
+messagenum = ru.string2int(message)
+messageblocks = ru.int2list(messagenum,n,endian="big")
def encrypt_block(blk):
return (blk ** e) % n
encrypted = [encrypt_block(block) for block in messageblocks]
-print(encrypted)
+print(ru.int2base64(ru.list2int(encrypted,n)))