-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (37 loc) · 1.32 KB
/
main.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
45
46
47
import rsa
def generate_keys():
public, private = rsa.generate_keys()
print('Public key: \n e = \n' + str(public[0]) + '\n n = \n' + str(public[1]))
print('Private key: \n d = \n' + str(private[0]) + '\n n = \n' + str(private[1]))
def encrypt_main():
print('Give me your public key:')
e = int(input('e = \n'))
n = int(input('n = \n'))
public = (e, n)
text = input('Type the text you want to encrypt: \n')
encrypted_text = rsa.encrypt(public, text)
print('The encrypted text: \n' + str(encrypted_text))
def decrypt_main():
print('Give me your private key:')
d = int(input('d = \n'))
n = int(input('n = \n'))
private = (d, n)
encrypted = input('Type the encrypted text: \n')
decrypted_text = rsa.decrypt(private, int(encrypted))
print('The decrypted text: \n' + decrypted_text)
def rsa_main():
print('\nChoose from the following options:: \n (1) Key genereation \n (2) Encryption \n (3) Decryption \n (Anything else) Quit')
choice = input()
if choice == '1':
generate_keys()
rsa_main()
elif choice == '2':
encrypt_main()
rsa_main()
elif choice == '3':
decrypt_main()
rsa_main()
else:
print('Goodbye!')
print('Hello! I am a simple program demonstrating RSA encryption technique!')
rsa_main()