luckydonald

mono.py

Feb 20th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import argparse
  2.  
  3. parser = argparse.ArgumentParser(
  4.     description='Encrypt or decrypt text files with monoalphabetic substitution cipher',
  5.     epilog="Example usage: "
  6.            "$ python3 mono.py --encrypt '/QWERTZ*LKJHGFDSAÄÖÜMNBVCX' ex2_mono.plaintext.txt "
  7.            "--out ex2_mono.outputtext.txt"
  8. )
  9. group = parser.add_mutually_exclusive_group(required=True)
  10. group.add_argument('--encrypt', metavar='KEY', action='store', dest='encrypt_key', type=str,
  11.                     help='key used for encryption')
  12. group.add_argument('--decrypt', metavar='KEY', action='store', dest='decrypt_key', type=str,
  13.                     help='key used for decryption')
  14. parser.add_argument('--out', metavar="OUTPUT_FILE", dest='output', default='-', action='store',
  15.                     type=argparse.FileType('w', encoding='UTF-8'),
  16.                     help='text is written to the given output file or, if not specified, to standard output')
  17. parser.add_argument('INPUT_FILE', type=argparse.FileType('r'), help='the input file to encrypt/decrypt')
  18. args = parser.parse_args()
  19.  
  20. if args.encrypt_key:
  21.     encrypt(args.encrypt_key, args.INPUT_FILE, args.output)
  22. else:
  23.     decrypt(args.decrypt_key, args.INPUT_FILE, args.output)
  24. # end if
Advertisement
Add Comment
Please, Sign In to add comment