Advertisement
Guest User

Encrypt/Decrypt function

a guest
May 16th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. ## My take on an encrypt/decrypt function
  2.  
  3.  
  4.  
  5. # Function to encrypt/decrypt a file
  6. def crypt(File2):
  7.     # Encrypt keys. Must be the same length and not contain values from each other
  8.     Alphabet    = 'abcdefghijklmnopqrstuvwxyz'
  9.     EncAlphabet = '1*2/3-4%5<6!7+8$9^0=&,`." '
  10.  
  11.     # List to hold the en/decrypted file
  12.     EncList = []
  13.    
  14.     # Loop through each letter in our file. If the letter is one key, find the position in the key and
  15.     # get the character at the same position in the other key and add it to our List. If the character
  16.     # is not in our key, then just copy it over.
  17.     for letter in File2:
  18.         if letter in Alphabet:
  19.             index = Alphabet.index(letter)
  20.             EncLetter = EncAlphabet[index]
  21.             EncList.append(EncLetter)
  22.         elif letter in EncAlphabet:
  23.             index = EncAlphabet.index(letter)
  24.             EncLetter = Alphabet[index]
  25.             EncList.append(EncLetter)
  26.         else:
  27.             EncList.append(letter)
  28.  
  29.     # Convert our list to a string and return it
  30.     Cryptstring = "".join(EncList)
  31.     return Cryptstring
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement