Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import math
  2. import random
  3.  
  4. def IsPrime(n):
  5.   d = 2
  6.   while (n % d) != 0:
  7.     d += 1
  8.   return d == n
  9.  
  10. p = 3
  11. q = 11
  12.  
  13. n = p * q
  14.  
  15. phi_n = (p-1)*(q-1)
  16.  
  17. #e = random.randint(2, phi_n)
  18. e = 7
  19. #while (math.gcd(e, n) != 1) or (not IsPrime(e)):
  20.   #e = random.randint(2, phi_n)
  21.  
  22. print("e =", e)
  23.  
  24. d = 2
  25. while ((e*d)%phi_n != 1) or not(d != n):
  26.   d += 1
  27.  
  28. print("phi_n =", phi_n)
  29. print("d =", d)
  30.  
  31. test_str = "Тестовый текст"
  32.  
  33. arr = [ord(i) for i in test_str]
  34. print("code", arr)
  35. arr = [(i**e)%n for i in arr] #шифровка
  36.  
  37. print("-".join(map(str, arr)))
  38.  
  39. arr = [(i**d)%n for i in arr] #дешифровка
  40. print("uncode", arr)
  41. arr = [chr(int(i)) for i in arr]
  42. print(arr)
  43. print("".join(arr))
  44.  
  45. print((29**d))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement