forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptsys.py
84 lines (57 loc) · 1.98 KB
/
encryptsys.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
import string
from random import randint
def decrypt():
texto = input("Input the text to decrypt : ").split(".")
abecedario = string.printable + "áéíóúÁÉÍÚÓàèìòùÀÈÌÒÙäëïöüÄËÏÖÜñÑ´"
abecedario2 = []
nummoves = int(texto[0])
indexs = []
finalindexs = []
textode1 = texto[1]
textode2 = []
for l in range(0, len(abecedario)):
abecedario2.append(abecedario[l])
for letter in range(0, len(textode1)):
textode2.append(textode1[letter])
for index in range(0, len(textode1)):
indexs.append(abecedario.index(textode1[index]))
for move in range(nummoves, 0):
abecedario2 += abecedario2.pop(27)
for value in indexs:
newval = value - nummoves
finalindexs.append(newval)
textofin = ""
for i in range(0, len(finalindexs)):
textofin += abecedario2[finalindexs[i]]
print(textofin)
def encrypt():
texto = input("Input the text to encrypt : ")
abecedario = string.printable + "áéíóúÁÉÍÚÓàèìòùÀÈÌÒÙäëïöüÄËÏÖÜñÑ´"
abecedario2 = []
nummoves = randint(1, len(abecedario))
indexs = []
texttoenc = []
for l in range(0, len(abecedario)):
abecedario2.append(abecedario[l])
for let in range(0, len(texto)):
texttoenc.append(texto[let])
for letter in texto:
indexs.append(abecedario2.index(letter))
for move in range(0, nummoves):
abecedario2 += abecedario2.pop(0)
texto = []
for i in range(0, len(indexs)):
texto.append(abecedario2[indexs[i]])
texto.append(".")
fintext = ""
for letter2 in range(0, len(texto), 2):
fintext += texto[letter2]
fintext = str(nummoves) + "." + fintext
print("\Encrypted text : " + fintext)
sel = input("What would you want to do?\n\n[1] Encrypt\n[2] Decrypt\n\n> ").lower()
if sel in ["1", "encrypt"]:
encrypt()
elif sel in ["2", "decrypt"]:
decrypt()
else:
print("Unknown selection.")