Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("""== Caesar's encryption/decryption algorythm ==
- To switch between encryption/decryption modes, enter a single 'e' or 'd'.
- To input encryption key, enter a number 1...25.
- To quit, enter 0.""")
- def cipher(t):
- d = {chr(ord('a')+i):chr(ord('a')+(i+key*encrypt)%26) for i in range(26)}
- d.update({chr(ord('A')+i):chr(ord('A')+(i+key*encrypt)%26) for i in range(26)})
- return ''.join([d[c] if c.isalpha() else c for c in t])
- go_on = True
- encrypt = 1
- key = 0
- while go_on:
- u = input()
- if u in [str(i+1) for i in range(25)]:
- key = int(u)
- print('<Encryption key switched to %d>'%key)
- elif u == '0':
- go_on = False
- print('<Quit>')
- elif u == 'e':
- encrypt = 1
- print('<Switched to encryption mode>')
- elif u == 'd':
- encrypt = -1
- print('<Switched to decryption mode>')
- else:
- print(cipher(u))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement