Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def encrypt_vigenere(plaintext:str,keyword:str) -> str:
- a = ('abcdefghijklmnopqrstuvwxyz')
- ciphertext=str()
- s = 0
- for i in plaintext:
- if i != (' '):
- ciphertext += str(a[(a.index(i)+a.index(keyword[s%len(keyword)]))%26])
- else:
- ciphertext+=(' ')
- s += 1
- print(ciphertext)
- return(ciphertext)
- def decrypt_vigenere(ciphertext:str,keyword:str) -> str:
- a = ('abcdefghijklmnopqrstuvwxyz')
- plaintex=str()
- s = 0
- for i in ciphertext:
- if i != (' '):
- plaintex += str(a[(a.index(i)-a.index(keyword[s%len(keyword)]))%26])
- else:
- plaintex+=(' ')
- s += 1
- print(plaintex)
- return(plaintex)
- x = input('Enter text: ')
- y = input('Enter keyword: ')
- g = input('Do you want do encrypt this text?(yes/no):')
- if g == ('yes'):
- encrypt_vigenere (x,y)
- elif g ==('no'):
- decrypt_vigenere(x,y)
- else:
- print('incorret input')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement