-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcriptografia2
More file actions
executable file
·81 lines (80 loc) · 1.83 KB
/
Copy pathcriptografia2
File metadata and controls
executable file
·81 lines (80 loc) · 1.83 KB
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
#!/home/rfa/anaconda3/bin/python3
#program for crypt and uncrypt informations
file1 = open('encriptado','r')
file2 = open('decriptado','r')
def decrypt(text):
text=text.replace(" ","")
exam=list(text)
lista=[];i=0
for ch in exam:
if ch == "#":
lista.append(ch)
else:
value=ord(str(ch))
if i % 2 == 0:
value = value - 7
else:
value = value + 7
lista.append(chr(value))
i+=1
decriptado=("".join(lista).strip('[]'))
decriptado=decriptado.replace("#"," ")
return decriptado
def encrypt(text):
exam=list(text)
lista=[];i=0
nova_lista=[]
for ch in exam:
if ch == " ":
value = ord("#")
else:
value=ord(str(ch))
if i % 2 == 0:
value = value + 7
else:
value = value - 7
lista.append(chr(value))
i+=1
i=0
for ch in lista:
nova_lista.append(ch)
if i == 4:
nova_lista.append(" ")
i=-1
i+=1
encriptado=("".join(nova_lista).strip('[]'))
return encriptado
x=0
frasechave=('O professor Carlos fará uma prova difícil.')
while(x == 0):
inicio=int(input('Deseja encriptar (1) ou desencriptar (2)'+'\n'))
if inicio == 1:
teste_a=int(input('Digitar a mensagem (1) ou usar a "frasechave"(2)'+'\n'))
if teste_a == 1:
vartexto=(input('Digite o valor a ser encriptado'+'\n'))
secret=encrypt(vartexto)
file1 = open('encriptado','w')
file1.write(secret)
x=1
elif teste_a == 2:
secret=encrypt(frasechave)
print(secret)
file1 = open('encriptado','w')
file1.write(secret)
x=1
elif inicio == 2:
middle=int(input('Digitar a mensagem (1) ou importar do arquivo (2)'+'\n'))
if middle == 1:
real=decrypt(input('Digite a mensagem a ser decriptada'+'\n'))
file2 = open('decriptado','w')
file2.write(real)
x=1
elif middle == 2:
linha = file1.readline()
real=decrypt(linha)
print(real)
file2 = open('decriptado','w')
file2.write(real)
x=1
else:
x=0