Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/RSA-code/Python/rsa-code.py
Normal file
25
Task/RSA-code/Python/rsa-code.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import binascii
|
||||
|
||||
n = 9516311845790656153499716760847001433441357 # p*q = modulus
|
||||
e = 65537
|
||||
d = 5617843187844953170308463622230283376298685
|
||||
|
||||
message='Rosetta Code!'
|
||||
print('message ', message)
|
||||
|
||||
hex_data = binascii.hexlify(message.encode())
|
||||
print('hex data ', hex_data)
|
||||
|
||||
plain_text = int(hex_data, 16)
|
||||
print('plain text integer ', plain_text)
|
||||
|
||||
if plain_text > n:
|
||||
raise Exception('plain text too large for key')
|
||||
|
||||
encrypted_text = pow(plain_text, e, n)
|
||||
print('encrypted text integer ', encrypted_text)
|
||||
|
||||
decrypted_text = pow(encrypted_text, d, n)
|
||||
print('decrypted text integer ', decrypted_text)
|
||||
|
||||
print('message ', binascii.unhexlify(hex(decrypted_text)[2:]).decode()) # [2:] slicing, to strip the 0x part
|
||||
Loading…
Add table
Add a link
Reference in a new issue