Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. question_str = "Y"
  2.  
  3. while question_str == "Y" :
  4.  
  5. result_str = "" #Empty string for the result of the encryption or decryption
  6.  
  7. message_str = input("Enter Message: ")
  8.  
  9. shift_str = int(input("Enter shift amount: "))
  10.  
  11. code_str = input("Encode (E) or Decode (D)? ")
  12.  
  13. if code_str == "E" :
  14.  
  15. message_str = message_str.replace('e', 'zw')
  16. #CREATE SPECIAL ZERO RULE
  17. middle_int = len(message_str)//2
  18.  
  19. message_str = ('hokie' + message_str[:middle_int] + 'hokie' + message_str[middle_int:] + 'hokie')
  20.  
  21. for e in message_str :
  22.  
  23. char_int = ord(e)
  24.  
  25. char_int_changed = ord(e)
  26.  
  27. if e.isalpha() :
  28.  
  29. if e.isupper() :
  30.  
  31. for x in range(char_int, char_int + shift_str) :
  32.  
  33. char_int_changed += 1
  34.  
  35. if char_int_changed > 90 :
  36.  
  37. char_int_changed = 65
  38.  
  39. result_str = result_str + chr(char_int_changed)
  40.  
  41. elif e.islower() :
  42.  
  43. for x in range(char_int, char_int + shift_str) :
  44.  
  45. char_int_changed += 1
  46.  
  47. if char_int_changed > 122 :
  48.  
  49. char_int_changed = 97
  50.  
  51. result_str = result_str + chr(char_int_changed)
  52.  
  53. else:
  54.  
  55. result_str = result_str + chr(char_int_changed)
  56.  
  57. print("Result: ", result_str)
  58.  
  59. elif code_str == "D" :
  60.  
  61. decrypt_str = ""
  62.  
  63. for e in message_str :
  64.  
  65. char_int = ord(e)
  66.  
  67. char_int_changed = ord(e)
  68.  
  69. if e.isalpha() :
  70.  
  71. if e.isupper() :
  72.  
  73. for x in range(char_int, char_int - shift_str) :
  74.  
  75. char_int_changed -= 1
  76.  
  77. if char_int_changed < 65 :
  78.  
  79. char_int_changed = 90
  80.  
  81. decrypt_str = decrypt_str + chr(char_int_changed)
  82.  
  83. if e.islower() :
  84.  
  85. for x in range(char_int, char_int - shift_str) :
  86.  
  87. char_int_changed -= 1
  88.  
  89. if char_int_changed < 97 :
  90.  
  91. char_int_changed = 122
  92.  
  93. decrypt_str = decrypt_str + chr(char_int_changed)
  94.  
  95. else:
  96.  
  97. decrypt_str = decrypt_str + chr(char_int_changed)
  98.  
  99. print(decrypt_str)
  100.  
  101.  
  102. middle_str = len(decrypt_str)//2
  103.  
  104. if middle_str % 2 == 0 :
  105.  
  106. middle_str -= 3
  107.  
  108. else:
  109.  
  110. middle_str -= 2
  111.  
  112. result_str = decrypt_str[5:middle_str] + decrypt_str[middle_str+5:len(decrypt_str)-5]
  113.  
  114. result_str = result_str.replace('zw','e')
  115.  
  116. print("Result: ", result_str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement