-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsa.py
44 lines (36 loc) · 1.11 KB
/
rsa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python
#
# selasa 26 juni 2018 by Hendriyawan
# copyrights 2018 gdev
# python 2.7.12
from core import RSA
from core import console
import sys
console.set_windowTitle('RSA-Encryption')
console.Banner()
cons = console.pyConsole()
rsa = RSA.RSAEncryption()
def main():
# generate keypair
# pasangan kunci public dan private
# kunci public : (e, n)
# kunci private : (d, n)
print(cons.Proc('generate keypair...'))
public_key, private_key = rsa.gen_key()
print(cons.Proc('e : public key : %s' % str(public_key)))
print(cons.Proc('d : private key : %s' % str(private_key)))
message = raw_input(cons.Proc('Enter your message : '))
if len(message) == 0:
print(cons.Err('please enter your message ! \n'))
sys.exit(1)
else:
ciphertext = rsa.encrypt(public_key, message)
plaintext = rsa.decrypt(private_key, ciphertext)
encrypted = ''.join(map(lambda x: str(x), ciphertext))
decrypted = ''.join(plaintext)
print('')
print(cons.print_c('Encrypted message : %s' % str(encrypted)))
print(cons.print_m('Decrypted message : %s' % str(decrypted)))
print('')
if __name__ == '__main__':
main()