Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. def encrypt_vigenere(plaintext:str,keyword:str) -> str:
  2. a = ('abcdefghijklmnopqrstuvwxyz')
  3. ciphertext=str()
  4. s = 0
  5. for i in plaintext:
  6. if i != (' '):
  7. ciphertext += str(a[(a.index(i)+a.index(keyword[s%len(keyword)]))%26])
  8. else:
  9. ciphertext+=(' ')
  10. s += 1
  11. print(ciphertext)
  12. return(ciphertext)
  13. def decrypt_vigenere(ciphertext:str,keyword:str) -> str:
  14. a = ('abcdefghijklmnopqrstuvwxyz')
  15. plaintex=str()
  16. s = 0
  17. for i in ciphertext:
  18. if i != (' '):
  19. plaintex += str(a[(a.index(i)-a.index(keyword[s%len(keyword)]))%26])
  20. else:
  21. plaintex+=(' ')
  22. s += 1
  23. print(plaintex)
  24. return(plaintex)
  25. x = input('Enter text: ')
  26. y = input('Enter keyword: ')
  27. g = input('Do you want do encrypt this text?(yes/no):')
  28. if g == ('yes'):
  29. encrypt_vigenere (x,y)
  30. elif g ==('no'):
  31. decrypt_vigenere(x,y)
  32. else:
  33. print('incorret input')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement