Advertisement
biswasrohit20

sw

May 31st, 2021
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. def swap_pair(string, pair):
  2. text = string.replace(pair[0], pair[1])
  3. return text
  4.  
  5.  
  6. def swap_adj(string):
  7. if len(string) % 2 == 1:
  8. string = string[0:-1]
  9. text = ""
  10. odds = ""
  11. evens = ""
  12. for i in range(len(string)):
  13. if i % 2 == 1:
  14. odds += string[i]
  15. else:
  16. evens += string[i]
  17. for i in range(len(odds)):
  18. text += odds[i]
  19. text += evens[i]
  20. return text
  21.  
  22.  
  23. def finalize(sting):
  24. text = sting
  25. while True:
  26. if text[0] == " ":
  27. text = text[1:]
  28. elif text[-1] == " ":
  29. text = text[:-1]
  30. else:
  31. break
  32. text = swap_pair(text, "z ")
  33. text = text[-1].upper() + text[:-1].lower() + "A+."
  34. return text
  35.  
  36. print(finalize(" CORE: zs "))
  37.  
  38. def decode_string(string, pair):
  39. print("Original", string)
  40. swapped_pair = swap_pair(string,pair)
  41. swapped_adj = swap_adj(swapped_pair)
  42. print("Final: ", finalize(swapped_adj))
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement