Skip to content

Instantly share code, notes, and snippets.

@dungwinux
Created March 15, 2019 12:44
Show Gist options
  • Save dungwinux/969c7bbd1ecacb10a0b6aa528ec65afb to your computer and use it in GitHub Desktop.
Save dungwinux/969c7bbd1ecacb10a0b6aa528ec65afb to your computer and use it in GitHub Desktop.
Encode and decode Themis config files
import zlib
from sys import argv
def decode(s):
dec = zlib.decompress(s)
res = dec.decode("utf-8")
return res
def encode(s):
enc = zlib.compress(s)
return enc
if __name__ == "__main__":
with open(argv[1], "rb") as fi:
s = fi.read()
if argv[1][-4:] == ".xml":
out = encode(s)
with open(argv[1][:-4], "wb") as fo:
fo.write(out)
else:
out = decode(s)
with open(argv[1] + ".xml", "w", encoding="utf-8") as fo:
fo.write(out)
@dungwinux
Copy link
Author

Credit to @TrungNguyen1909 for the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment