aboutsummaryrefslogtreecommitdiff
path: root/final/RSA.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.py
parente60926a2bfa1fee117c7d2175a7963b02801c16f (diff)
parentc8e69070fbd09863b563730630e7f60fe44d7dac (diff)
Merge branch 'master' of https://github.com/feynmansfedora/appcomb-proj
Diffstat (limited to 'final/RSA.py')
-rw-r--r--final/RSA.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/final/RSA.py b/final/RSA.py
index c12e94f..82a3211 100644
--- a/final/RSA.py
+++ b/final/RSA.py
@@ -1,4 +1,5 @@
import random
+from math import gcd as bltin_gcd
def isPrime(x):
pr = True
for j in range(2, x):
@@ -9,25 +10,33 @@ def remove_char(input_string, index):
first_part = input_string[:index]
second_part - input_string[index+1:]
return first_part + second_part
+def coprime(a, b):
+ return bltin_gcd(a, b) == 1
+
primes = [i for i in range(2,1000) if isPrime(i)]
p = random.choice(primes)
q = random.choice(primes)
n = p * q
-print(n)
+coprimes = [j for j in range(2,n) if coprime(j, ((p-1)*(q-1)))]
+e = random.choice(coprimes)
string = input()
sepChars = list(string)
numChars = 0
+
for c in sepChars:
numChars += ((128**sepChars.index(c))*ord(c))
-print(numChars)
-blocks = []
+print("numChars:",numChars)
c = 0
-for j in range(0, n-1):
- blocks.append(str(numChars)[j:j+1])
-for j in range(n-1, len(str(numChars))):
- blocks[(len(str(n))-1)%j] = blocks[(len(str(n))-1)%j] + str(numChars)[j:j+1]
+blocks = []
-print(blocks)
-
+while numChars > 0:
+ blocks.append(numChars%n)
+ numChars = (numChars-numChars%n)/n
+
+print("Blocks:",blocks)
+encryptedBlocks = []
+for b in blocks:
+ encryptedBlocks.append((b**e)%n)
+print("Encrypted:",encryptedBlocks)