Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- parser = argparse.ArgumentParser(description="Vigenere cipher tool")
- parser.add_argument('-e', '--encrypt', action='store_true', help='Encrypt ASCII message')
- parser.add_argument('-d', '--decrypt', action='store_true' , help = "Decrypt ASCII message")
- args = parser.parse_args()
- def encrypt(plaintext, shift):
- ciphertext = ''
- for i in range(len(plaintext)):
- ciphertext += chr(ord(plaintext[i]) + shift % 26)
- print(ciphertext)
- def decrypt(ciphertext, shift):
- plaintext = ''
- for i in range(len(ciphertext)):
- plaintext += chr(ord(ciphertext[i]) - shift % 26)
- print(plaintext)
- def main():
- if args.encrypt:
- plaintext = raw_input('Enter plaintext: ').upper()
- shift = int(raw_input('Enter shift: '))
- encrypt(plaintext, shift)
- if args.decrypt:
- ciphertext = raw_input('Enter ciphertext: ').upper()
- shift = int(raw_input('Enter shift: '))
- decrypt(ciphertext, shift)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement