Created
May 16, 2025 02:35
-
-
Save penut85420/ffc88913f3d728f27800d2a63525df1b to your computer and use it in GitHub Desktop.
A simple encoder/decoder using Base64 and Gzip.
This file contains hidden or 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 base64 | |
| import gzip | |
| import fire | |
| def encode_text(src_path, dst_path="encode.txt"): | |
| with open(src_path, "rb") as fp: | |
| data = fp.read() | |
| data = gzip.compress(data) | |
| data = base64.b64encode(data) | |
| data = data.decode("UTF-8") | |
| with open(dst_path, "wt", encoding="UTF-8") as fp: | |
| fp.write(data) | |
| def decode_text(src_path="encode.txt", dst_path="decode.txt"): | |
| with open(src_path, "rt", encoding="UTF-8") as fp: | |
| data = fp.read() | |
| data = data.encode("UTF-8") | |
| data = base64.b64decode(data) | |
| data = gzip.decompress(data) | |
| with open(dst_path, "wb") as fp: | |
| fp.write(data) | |
| if __name__ == "__main__": | |
| fire.Fire(dict(encode=encode_text, decode=decode_text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment