Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. my_alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2. def rotate(x , y):
  3. z = my_alp.find(x)
  4. if ((z + y) > 25):
  5. w = (z + y) % 26
  6. return my_alp(w)
  7. return my_alp(z + y)
  8. def cencrypt(x , y):
  9. x = x.upper()
  10. if len(x) == 1:
  11. return rotate(x , y)
  12. def c_encrypt(x , y):
  13. x = x.upper()
  14. c= cencrypt(x , y)
  15. return c
  16. def cdecrypt(string , key):
  17. string = string.upper()
  18. if len(string) == 1:
  19. return rotate(string , key * -1)
  20. def c_decrypt(string , key):
  21. string = string.upper()
  22. new_string = cdecrypt(string , key * -1)
  23. return new_string
  24. def vig_rotate(x , y):
  25. first_index = my_alp.find(x.upper())
  26. last_index = (first_index +y) % 26
  27. return(my_alp(last_index))
  28. def vig_encrypt(x , y):
  29. encryption = ''
  30. for character in x:
  31. if character.isalpha():
  32. encryption += vig_rotate(character , y)
  33. else:
  34. encryption += character
  35. return(encryption)
  36. def vig_decrypt(x , y):
  37. encryption = ''
  38. for character in x:
  39. if character.isalpha():
  40. encryption += vig_rotate(character , y * -1)
  41. else:
  42. encryption += character
  43. return encryption
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement