Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. def main():
  3. #recieve sentence and shift from user
  4. x = input("Please enter a sentence to encrypt:\n")
  5. shift = int(input("Please enter the size of the shift:\n"))
  6. #add encrypted text to new list
  7. txt = []
  8. for i in range(len(x)):
  9. if x[i] == '#':
  10. txt.append('*')
  11. continue
  12. elif i == len(x)-1 and x[i] == '!':
  13. continue
  14. elif x[i] == '?':
  15. continue
  16. #
  17. elif (ord('A') <= ord(x[i]) <= ord('Z')) or (ord('a') <= ord(x[i]) <= ord('z')):
  18. if ord(x[i]) % 2 == 0:
  19. y = ord(x[i])
  20. for j in range(0,shift):
  21. if y == ord('z') or y == ord('Z'):
  22. y = ord('a')
  23. else:
  24. y += 1
  25. txt.append(chr(y).lower())
  26.  
  27. else:
  28. y = ord(x[i])
  29. for j in range(0,shift):
  30. if y == ord('a') or y == ord('A'):
  31. y = ord('Z')
  32. else:
  33. y -= 1
  34. txt.append(chr(y).upper())
  35. else:
  36. txt.append(x[i])
  37. print("".join(txt))
  38.  
  39. if __name__ == '__main__':
  40. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement