aboutsummaryrefslogtreecommitdiff
path: root/final/rsa-encrypt.py
diff options
context:
space:
mode:
authorholden watson <holdenew@gmail.com>2019-11-11 23:41:01 -0500
committerholden watson <holdenew@gmail.com>2019-11-11 23:41:01 -0500
commitdb732bd93ffc688e16a0d9e0eb2e321315fd4621 (patch)
tree926c4c0d654106bc1d09afd2e0541943addc4743 /final/rsa-encrypt.py
parente60926a2bfa1fee117c7d2175a7963b02801c16f (diff)
parentc8e69070fbd09863b563730630e7f60fe44d7dac (diff)
Merge branch 'master' of https://github.com/feynmansfedora/appcomb-proj
Diffstat (limited to 'final/rsa-encrypt.py')
-rw-r--r--final/rsa-encrypt.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/final/rsa-encrypt.py b/final/rsa-encrypt.py
new file mode 100644
index 0000000..a15fe9d
--- /dev/null
+++ b/final/rsa-encrypt.py
@@ -0,0 +1,24 @@
+'''p = 29
+q = 17
+n = p*q
+tot = (p-1)*(q-1)
+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 = 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
+
+def encrypt_block(blk):
+ return (blk ** e) % n
+
+encrypted = [encrypt_block(block) for block in messageblocks]
+print(encrypted)