-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
130 lines (111 loc) · 3.14 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /usr/bin/python3.4
import aes, elGamal
import sys, os
from time import sleep
try:
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
print("===========================================================")
print("==================== PYAES & PEL GAMAL ====================")
print("===========================================================")
print("\n")
print("Please choose one encryption method:")
print("1- AES: Advanced (symetric) Encryption Standard")
print("2- El Gamal: Asymetric encryption")
print("3- El Gamal: File signature")
print("4- Exit")
algo = input()
algo = int(algo)
while (algo < 1 or algo > 4):
print("Please choose one encryption method:")
print("1- AES: Advanced (symetric) Encryption Standard")
print("2- El Gamal: Asymetric encryption")
print("3- El Gamal: File signature")
print("4- Exit")
algo = input()
algo = int(algo)
print("\n")
# AES
if (algo == 1):
print("Please select key size:")
print("1- 128 bits")
print("2- 192 bits")
print("3- 256 bits")
key = input()
key = int(key)
while (key < 1 or key > 3):
print("Please select key size:")
print("1- 128 bits")
print("2- 192 bits")
print("3- 256 bits")
key = input()
key = int(key)
if (key == 1):
key_size = 128
elif (key == 2):
key_size = 192
elif (key == 3):
key_size = 256
print("Do you want to crypt or uncrypt?")
print("1- Crypt")
print("2- Decrypt")
mode = input()
mode = int(mode)
while (mode < 1 or mode > 2):
print("Do you want to crypt or uncrypt?")
print("1- Crypt")
print("2- Decrypt")
mode = input()
mode = int(mode)
print("Please give me your filename (must be in the current directory):")
file = input()
while (not os.path.exists(str(file))):
print("Please give me your filename (must be in the current directory):")
file = input()
print("Please insert your password:")
pwd = input()
print("\n")
if (mode == 1):
aes.crypt(file, key_size, pwd)
elif (mode == 2):
aes.decrypt(file, key_size, pwd)
# El Gamal encryption
elif (algo == 2):
print("Do you want to crypt or uncrypt?")
print("1- Crypt")
print("2- Decrypt")
print("3- Key generation")
mode = input()
mode = int(mode)
while (mode < 1 or mode > 3):
print("Do you want to crypt or uncrypt?")
print("1- Crypt")
print("2- Decrypt")
print("3- Key generation")
mode = input()
mode = int(mode)
print("Please give me your filename (must be in the current directory):")
file = input()
while (not os.path.exists(str(file))):
print("Please give me your filename (must be in the current directory):")
file = input()
print("\n")
# Encryption
if(mode == 1):
elGamal.chiffreFic(file)
# Decryption
if(mode == 2):
elGamal.deChiffreFic(file)
# Key generation
if(mode == 3):
elGamal.keygen()
os.system("python3.4 main.py")
# El Gamal signature
elif (algo == 3):
print("Sorry, this feature is not implemented yet")
sleep(2)
os.system("python3.4 main.py")
elif (algo == 4):
print("Thank you for using PYAES et PEl Gamal")
exit()
except ValueError as err:
print(str(err))