-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencrypted.py
More file actions
executable file
·32 lines (29 loc) · 838 Bytes
/
Copy pathencrypted.py
File metadata and controls
executable file
·32 lines (29 loc) · 838 Bytes
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
chiaveDiCifratura = (2, 8, -1, 4)
chiavePerDecriptare = (-2, -8, 1, -4)
def cripta(stringa, chiave):
stringaCifrata = ""
i = 0
for lettera in stringa:
stringaCifrata += chr((ord(lettera) + chiave[i]) % 128)
i += 1
if i >= len(chiave):
i = 0
return stringaCifrata
def criptaFile(nomeFile):
f = open(nomeFile, "r")
contenuto = f.read()
f.close()
contenutoCriptato = cripta(contenuto, chiaveDiCifratura)
f = open(nomeFile, "w")
f.write(contenutoCriptato)
f.close()
def decriptaFile(nomeFile):
f = open(nomeFile, "r")
contenuto = f.read()
f.close()
contenutoCriptato = cripta(contenuto, chiavePerDecriptare)
f = open(nomeFile, "w")
f.write(contenutoCriptato)
f.close()
#criptaFile("cosedafare.txt")
#decriptaFile("cosedafare.txt")