Advertisement
Guest User

Untitled

a guest
May 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import random
  3. # Jeśli dostajesz błąd "ImportError: No module named gmpy2", możesz to naprawić
  4. # dzięki poleceniu
  5. # python3 -m pip install gmpy2
  6. from gmpy2 import is_prime, invert
  7. from sekrety import wiadomosc
  8.  
  9. pt = int.from_bytes(wiadomosc.encode(), 'big')
  10. size = 1024
  11.  
  12. p = random.randint(2**(size - 1), 2**size)
  13. while not is_prime(p):
  14. p += 1
  15. q = p * 17 + random.randint(0, 2**(size//2 + 15))
  16. while not is_prime(q):
  17. q += 1
  18.  
  19. N = p*q
  20. e = 0x10001
  21. d = invert(e, N - p - q + 1) # klucz prywatny
  22. ct = pow(pt, e, N)
  23.  
  24. print('Klucz publiczny (N, e) =', (N, e))
  25. print('Szyfrogram ct =', ct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement