Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import random
- # Jeśli dostajesz błąd "ImportError: No module named gmpy2", możesz to naprawić
- # dzięki poleceniu
- # python3 -m pip install gmpy2
- from gmpy2 import is_prime, invert
- from sekrety import wiadomosc
- pt = int.from_bytes(wiadomosc.encode(), 'big')
- size = 1024
- p = random.randint(2**(size - 1), 2**size)
- while not is_prime(p):
- p += 1
- q = p * 17 + random.randint(0, 2**(size//2 + 15))
- while not is_prime(q):
- q += 1
- N = p*q
- e = 0x10001
- d = invert(e, N - p - q + 1) # klucz prywatny
- ct = pow(pt, e, N)
- print('Klucz publiczny (N, e) =', (N, e))
- print('Szyfrogram ct =', ct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement