Skip to content

Instantly share code, notes, and snippets.

@tunelko
Last active July 24, 2025 13:52
Show Gist options
  • Save tunelko/49b7e64c1688d62d0ecd to your computer and use it in GitHub Desktop.
Save tunelko/49b7e64c1688d62d0ecd to your computer and use it in GitHub Desktop.
weird_encodings
import base64
import argparse
# Definición de variantes de codificación
atom128 = "/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC"
megan35 = "3GHIJKLMNOPQRSTUb=cdefghijklmnopWXYZ/12+406789VaqrstuvwxyzABCDEF5"
zong22 = "ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2"
hazz15 = "HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5"
b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
class B64weirdEncodings:
def __init__(self, translation):
base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
self.encode_map = dict(zip(base, translation))
self.decode_map = dict(zip(translation, base))
def encode(self, pt):
if isinstance(pt, str):
pt = pt.encode()
b64 = base64.b64encode(pt).decode()
return "".join(self.encode_map[x] for x in b64)
def decode(self, code):
try:
b64 = "".join(self.decode_map[x] for x in code)
return base64.b64decode(b64.encode()).decode(errors="replace")
except KeyError:
return "Not valid"
except TypeError:
return "Padding incorrect"
def process_all_variants(text, mode):
variants = {
"base64": b,
"atom128": atom128,
"megan35": megan35,
"hazz15": hazz15,
"zong22": zong22,
}
for name, charset in variants.items():
encoder = B64weirdEncodings(charset)
if mode == "enc":
result = encoder.encode(text)
elif mode == "dec":
result = encoder.decode(text)
else:
result = "Invalid mode"
print(f"{name}: {result}")
def main():
parser = argparse.ArgumentParser(description="Base64 encoder/decoder with custom variants")
parser.add_argument("text", help="Text to encode or decode")
parser.add_argument("mode", choices=["enc", "dec"], help="Mode: 'enc' to encode, 'dec' to decode")
args = parser.parse_args()
process_all_variants(args.text, args.mode)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment