Advertisement
Guest User

ceasar

a guest
Apr 10th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import argparse
  2.  
  3. parser = argparse.ArgumentParser(description="Vigenere cipher tool")
  4.  
  5. parser.add_argument('-e', '--encrypt', action='store_true', help='Encrypt ASCII message')
  6. parser.add_argument('-d', '--decrypt', action='store_true' , help = "Decrypt ASCII message")
  7.  
  8. args = parser.parse_args()
  9.  
  10. def encrypt(plaintext, shift):
  11.     ciphertext = ''
  12.     for i in range(len(plaintext)):
  13.         ciphertext += chr(ord(plaintext[i]) + shift % 26)
  14.     print(ciphertext)
  15.  
  16. def decrypt(ciphertext, shift):
  17.     plaintext = ''
  18.     for i in range(len(ciphertext)):
  19.         plaintext += chr(ord(ciphertext[i]) - shift % 26)
  20.     print(plaintext)
  21.  
  22. def main():
  23.     if args.encrypt:
  24.         plaintext = raw_input('Enter plaintext: ').upper()
  25.         shift = int(raw_input('Enter shift: '))
  26.         encrypt(plaintext, shift)
  27.     if args.decrypt:
  28.         ciphertext = raw_input('Enter ciphertext: ').upper()
  29.         shift = int(raw_input('Enter shift: '))
  30.         decrypt(ciphertext, shift)
  31.  
  32. if __name__ == "__main__":
  33.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement