Guest User

Untitled

a guest
Oct 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. """
  2. caesar_shift.py
  3.  
  4. MIT License
  5.  
  6. Copyright (c) 2017 andynines
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14.  
  15. The above copyright notice and this permission notice shall be included in all
  16. copies or substantial portions of the Software.
  17.  
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. SOFTWARE.
  25. """
  26.  
  27. from string import ascii_uppercase
  28.  
  29. ALPHABET = list(ascii_uppercase)
  30.  
  31. shift = lambda text, key: "".join([ALPHABET[(ALPHABET.index(character) + key) % len(ALPHABET)] if character in ALPHABET else character for character in text.upper()])
  32. crack = lambda text: [shift(text, key) for key in range(1, len(ALPHABET))]
  33.  
  34. def main():
  35. EXIT_COMMAND = "/e"
  36. print("Caesar Shift Cipher\nType {} to exit".format(EXIT_COMMAND))
  37. while True:
  38. message = input("\n>")
  39. if message == EXIT_COMMAND:
  40. break
  41. for index, character in enumerate(crack(message)):
  42. print("{}. {}".format(index + 1, character))
  43.  
  44. if __name__ == "__main__":
  45. main()
Add Comment
Please, Sign In to add comment