Created
October 18, 2022 19:44
-
-
Save 77/bf68f3ab214aece3c802527c2d10443d to your computer and use it in GitHub Desktop.
Simple Base85 encode/decode script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import base64 | |
import sys | |
parser = argparse.ArgumentParser() | |
parser.add_argument('command', choices=['encode', 'decode']) | |
parser.add_argument('--input', type=str, required=False) | |
parser.add_argument('--output', type=str, required=False) | |
args = parser.parse_args() | |
if not args.input: | |
input = sys.stdin | |
else: | |
input = open(args.input, "rb") | |
if not args.output: | |
output = sys.stdout | |
else: | |
output = open(args.output, "wb") | |
if args.command == 'encode': | |
data = input.read().encode("UTF-8") | |
result = base64.a85encode(data) | |
output.write(result.decode("UTF-8")) | |
elif args.command == 'decode': | |
data = input.read().encode("UTF-8") | |
result = base64.a85decode(data) | |
output.write(result.decode("UTF-8")) | |
input.close() | |
output.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment