Last active
August 6, 2022 16:33
-
-
Save Aravindha1234u/2d670d43b1668343ef0bbd981ff264a8 to your computer and use it in GitHub Desktop.
Generate CTF flag with 32 bit hex hash and L33t lang conversion with wrapping flag format
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
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import argparse | |
import random | |
import math | |
import random | |
char_map = [ | |
["A", "a", "4", "@"], | |
["B", "b", "8"], | |
["C", "c"], | |
["D", "d"], | |
["E", "e", "3"], | |
["F", "f"], | |
["G", "g", "6", "9"], | |
["H", "h"], | |
["I", "i", "1"], | |
["J", "j"], | |
["K", "k"], | |
["L", "l", "1"], | |
["M", "m"], | |
["N", "n"], | |
["O", "o", "0"], | |
["P", "p"], | |
["Q", "q"], | |
["R", "r"], | |
["S", "s", "5", "$"], | |
["T", "t", "7"], | |
["U", "u"], | |
["V", "v"], | |
["W", "w"], | |
["X", "x"], | |
["Y", "y"], | |
["Z", "z", "2"], | |
] | |
def change(c): | |
if c.isalpha(): | |
c = c.upper() | |
char_set = char_map[ord(c) - ord("A")] | |
new_c = char_set[random.randint(0, len(char_set) - 1)] | |
return new_c, (c == new_c) * math.log2(len(char_set)) | |
else: | |
return c, 0 | |
def main(): | |
global args | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--fmt", help="flag fomat", default="flag") | |
parser.add_argument("flag", help="origin flag") | |
args = parser.parse_args() | |
entropy = 0 | |
flag = "" | |
for c in args.flag: | |
new_c, e = change(c) | |
flag += new_c | |
entropy = e | |
md5hash = "%032x" % random.getrandbits(128) | |
flag = "_".join(flag.split()) | |
flag = "%s{%s}" % (args.fmt, f"{md5hash}_{flag}") | |
print(flag) | |
print(f"Added entropy: {entropy:.2f} bits") | |
if __name__ == "__main__": | |
main() | |
""" | |
python3 genflag.py "The End of the Road" | |
flag{0646e447c90a1ef09e572add4b4784b3_The_3Nd_Of_7he_r0@D} | |
Added entropy: 5.17 bits | |
python3 genflag.py --fmt winjactf "The End of the Road" | |
winjactf{25ffcf80db3b46d336a97f166f281d55_7hE_3nd_of_7HE_R0aD} | |
Added entropy: 6.17 bits | |
python3 genflag.py --fmt winja "The End of the Road" | |
winja{8499973e6659192b581e16f07bc1e9c7_Th3_3ND_Of_7hE_RO@d} | |
Added entropy: 9.34 bits | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment