Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- parser = argparse.ArgumentParser(
- description='Encrypt or decrypt text files with monoalphabetic substitution cipher',
- epilog="Example usage: "
- "$ python3 mono.py --encrypt '/QWERTZ*LKJHGFDSAÄÖÜMNBVCX' ex2_mono.plaintext.txt "
- "--out ex2_mono.outputtext.txt"
- )
- group = parser.add_mutually_exclusive_group(required=True)
- group.add_argument('--encrypt', metavar='KEY', action='store', dest='encrypt_key', type=str,
- help='key used for encryption')
- group.add_argument('--decrypt', metavar='KEY', action='store', dest='decrypt_key', type=str,
- help='key used for decryption')
- parser.add_argument('--out', metavar="OUTPUT_FILE", dest='output', default='-', action='store',
- type=argparse.FileType('w', encoding='UTF-8'),
- help='text is written to the given output file or, if not specified, to standard output')
- parser.add_argument('INPUT_FILE', type=argparse.FileType('r'), help='the input file to encrypt/decrypt')
- args = parser.parse_args()
- if args.encrypt_key:
- encrypt(args.encrypt_key, args.INPUT_FILE, args.output)
- else:
- decrypt(args.decrypt_key, args.INPUT_FILE, args.output)
- # end if
Advertisement
Add Comment
Please, Sign In to add comment