Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: cp1252 -*-
- """
- Caesar cipher
- Shifts the letter to be the letter that comes x step after it
- x = the key
- So if the key is 3 A would become D
- """
- #list of all letters from A-Z
- alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","Γ₯","Γ€","ΓΆ"]
- #list for text to encrypt
- norm_li = []
- #encrypted list
- ectd_li = []
- #decrypted list
- decr_li = []
- def encrypt(li, key):
- for i in li:
- norm_li.append(i)
- for x in norm_li:
- if x == " ":
- ectd_li.append("")
- for a in alphabet:
- if x.lower() == a.lower():
- if x == x.upper():
- ectd_li.append(alphabet[(len(alphabet)-(len(alphabet)-key))-1].upper())
- else:
- ectd_li.append(alphabet[(len(alphabet)-(len(alphabet)-key))-1])
- print "Encrypted text: ",
- for char in ectd_li:
- print char,
- def decrypt(li, key):
- for x in ectd_li:
- if x == "":
- decr_li.append("")
- for a in alphabet:
- if x.lower() == a.lower():
- if x == x.upper():
- decr_li.append(alphabet[alphabet.index(a)-key].upper())
- else:
- decr_li.append(alphabet[alphabet.index(a)-key])
- print "Decrypted text: ",
- for char in decr_li:
- print char,
- encrypt(raw_input("Text you want encrypted: "), input("Encryption key: "))
- print
- decrypt(ectd_li,input("Enter the right key to decrypt the message: "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement