Thanks Microsoft
Description
Analysis
Solution
import string
from textwrap import wrap
# Minified version of C function
def encode_char(char):
ln = ord(char) & 0x0F
hn = ord(char) >> 4 & 0x0F
x = 11 if hn <= 9 else 26
y = 14 if ln <= 9 else 26
if(hn > 9): hn -= 9
if(ln > 9): ln -= 9
return (((((0x0E << 6) | y) << 4) | ln) << 6 | x) << 4 | hn
ALPHABET = string.ascii_letters + string.digits + "{_}!" # Create alphabet
CIPHER = {encode_char(c): c for c in ALPHABET} # Build dictionary
msg = "e38cb5e394b6e38cb6e398b5e384b6e68cb6e688b7e68cb6e698b6e68cb6e698b5e390b7e3a0b6e384b4e390b7e698b5e39cb7e384b6e38cb7e698b5e694b6e698b6e698b5e394b6e694b6e38cb6e388b7e3a4b7e380b7e390b7e384b3e698b6e694b6e690b7"
# In C code output is printed as %x (hex) which seems to be 6 in length (1 Chunk)
# Chunk is converted to integer using `int`
# Encoded character is being looked up in dictionary
# Finally everything gets joined in one string
print("".join(CIPHER[int(chunk, 16)] for chunk in wrap(msg, 6)))Last updated