Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import random
- def IsPrime(n):
- d = 2
- while (n % d) != 0:
- d += 1
- return d == n
- p = 3
- q = 11
- n = p * q
- phi_n = (p-1)*(q-1)
- #e = random.randint(2, phi_n)
- e = 7
- #while (math.gcd(e, n) != 1) or (not IsPrime(e)):
- #e = random.randint(2, phi_n)
- print("e =", e)
- d = 2
- while ((e*d)%phi_n != 1) or not(d != n):
- d += 1
- print("phi_n =", phi_n)
- print("d =", d)
- test_str = "Тестовый текст"
- arr = [ord(i) for i in test_str]
- print("code", arr)
- arr = [(i**e)%n for i in arr] #шифровка
- print("-".join(map(str, arr)))
- arr = [(i**d)%n for i in arr] #дешифровка
- print("uncode", arr)
- arr = [chr(int(i)) for i in arr]
- print(arr)
- print("".join(arr))
- print((29**d))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement