Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## My take on an encrypt/decrypt function
- # Function to encrypt/decrypt a file
- def crypt(File2):
- # Encrypt keys. Must be the same length and not contain values from each other
- Alphabet = 'abcdefghijklmnopqrstuvwxyz'
- EncAlphabet = '1*2/3-4%5<6!7+8$9^0=&,`." '
- # List to hold the en/decrypted file
- EncList = []
- # Loop through each letter in our file. If the letter is one key, find the position in the key and
- # get the character at the same position in the other key and add it to our List. If the character
- # is not in our key, then just copy it over.
- for letter in File2:
- if letter in Alphabet:
- index = Alphabet.index(letter)
- EncLetter = EncAlphabet[index]
- EncList.append(EncLetter)
- elif letter in EncAlphabet:
- index = EncAlphabet.index(letter)
- EncLetter = Alphabet[index]
- EncList.append(EncLetter)
- else:
- EncList.append(letter)
- # Convert our list to a string and return it
- Cryptstring = "".join(EncList)
- return Cryptstring
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement