Skip to content

Instantly share code, notes, and snippets.

@DavidBuchanan314
Last active May 16, 2024 14:00
Show Gist options
  • Save DavidBuchanan314/07da147445a90f7a049d1b9b3e3dc6f3 to your computer and use it in GitHub Desktop.
Save DavidBuchanan314/07da147445a90f7a049d1b9b3e3dc6f3 to your computer and use it in GitHub Desktop.
ZALGO_CHARS = "\u0300\u0301\u0302\u0303\u0304\u0305\u0306\u0307\u0308\u0309\u030a\u030b\u030c\u030d\u030e\u030f\u0310\u0311\u0312\u0313\u0314\u0315\u0316\u0317\u0318\u0319\u031a\u031b\u031c\u031d\u031e\u031f\u0320\u0321\u0322\u0323\u0324\u0325\u0326\u0327\u0328\u0329\u032a\u032b\u032c\u032d\u032e\u032f\u0330\u0331\u0332\u0333\u0334\u0335\u0336\u0337\u0338\u0339\u033a\u033b\u033c\u033d\u033e\u033f\u0340\u0341\u0342\u0343\u0344\u0345\u0346\u0347\u0348\u0349\u034a\u034b\u034c\u034d\u034e\u0350\u0351\u0352\u0353\u0354\u0355\u0356\u0357\u0358\u0359\u035a\u035b\u035c\u035d\u035e\u035f\u0360\u0361\u0362\u0363\u0364\u0365\u0366\u0367\u0368\u0369\u036a\u036b\u036c\u036d\u036e\u036f\u0483\u0484\u0485\u0486\u0487\u0591\u0592\u0593\u0594\u0595\u0596\u0597\u0598\u0599\u059a\u059b\u059c\u059d\u059e\u059f\u05a0\u05a1\u05a2\u05a3\u05a4\u05a5\u05a6\u05a7\u05a8\u05a9\u05aa\u05ab\u05ac\u05ad\u05ae\u05af\u05b0\u05b1\u05b2\u05b3\u05b4\u05b5\u05b6\u05b7\u05b8\u05b9\u05ba\u05bb\u05bc\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610\u0611\u0612\u0613\u0614\u0615\u0616\u0617\u0618\u0619\u061a\u064b\u064c\u064d\u064e\u064f\u0650\u0651\u0652\u0653\u0654\u0655\u0656\u0657\u0658\u0659\u065a\u065b\u065c\u065d\u065e\u065f\u0670\u06d6\u06d7\u06d8\u06d9\u06da\u06db\u06dc\u06df\u06e0\u06e1\u06e2\u06e3\u06e4\u06e7\u06e8\u06ea\u06eb\u06ec\u06ed\u0711\u0730\u0731\u0732\u0733\u0734\u0735\u0736\u0737\u0738\u0739\u073a\u073b\u073c\u073d\u073e\u073f\u0740\u0741\u0742\u0743\u0744\u0745\u0746\u0747\u0748\u0749\u074a\u07eb\u07ec\u07ed\u07ee\u07ef\u07f0\u07f1\u07f2\u07f3"
LOOKUP = {c:i for i, c in enumerate(ZALGO_CHARS)}
def encode(data: bytes) -> str:
result = ""
for i, x in enumerate(data):
if (i % 32 == 0):
result += "A" # TODO: additionally, encode data here using b64
result += ZALGO_CHARS[x]
return result
def decode(str_in: str) -> bytes:
out = []
for char in str_in:
if char in LOOKUP:
out.append(LOOKUP[char])
return bytes(out)
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print(f"USAGE: python3 {sys.argv[0]} enc|dec")
exit()
arg = sys.argv[1]
if arg in ["e", "enc"]:
print(encode(sys.stdin.buffer.read()))
elif arg in ["d", "dec"]:
sys.stdout.buffer.write(decode(sys.stdin.read()))
sys.stdout.buffer.flush()
else:
print(f"unrecognised option: {arg}", file=sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment