SHARE
TWEET

Basi Di Crittografia #3 - Codice 2

Driverfury Mar 2nd, 2016 319 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. chiaveDiCifratura = (2, 8, -1, 4)
  2. chiavePerDecriptare = (-2, -8, 1, -4)
  3.  
  4. def cripta(stringa, chiave):
  5.     stringaCifrata = ""
  6.     i = 0
  7.     for lettera in stringa:
  8.         stringaCifrata += chr((ord(lettera) + chiave[i]) % 128)
  9.         i += 1
  10.         if i >= len(chiave):
  11.             i = 0
  12.     return stringaCifrata
  13.  
  14. def criptaFile(nomeFile):
  15.     f = open(nomeFile, "r")
  16.     contenuto = f.read()
  17.     f.close()
  18.     contenutoCriptato = cripta(contenuto, chiaveDiCifratura)
  19.     f = open(nomeFile, "w")
  20.     f.write(contenutoCriptato)
  21.     f.close()
  22.  
  23. def decriptaFile(nomeFile):
  24.     f = open(nomeFile, "r")
  25.     contenuto = f.read()
  26.     f.close()
  27.     contenutoCriptato = cripta(contenuto, chiavePerDecriptare)
  28.     f = open(nomeFile, "w")
  29.     f.write(contenutoCriptato)
  30.     f.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top