Advertisement
brilliant_moves

CaesarCipher2.py

Jun 11th, 2015
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/python
  2. #CaesarCipher2.py
  3. #Python 2.7
  4.  
  5. cipher = ''
  6. alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  7. 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  8.  
  9. message = raw_input ("What message would you like to encrypt? ... ").lower()
  10. shift = int (input ("What is the shift key? ... "))
  11. for c in message:
  12.     if c.isalpha():
  13.         cipher += alphabet [(alphabet.index (c) + shift) % (len (alphabet))]
  14.     else:
  15.         cipher += c
  16.        
  17. print cipher
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement