Skip to content

Instantly share code, notes, and snippets.

@Wind010
Last active January 15, 2024 04:04
Show Gist options
  • Select an option

  • Save Wind010/a33daa7c2a687bf06cda9f8b9bae79d7 to your computer and use it in GitHub Desktop.

Select an option

Save Wind010/a33daa7c2a687bf06cda9f8b9bae79d7 to your computer and use it in GitHub Desktop.
Transformation PicoCTF reverse engineering challenge
enc_dec = [28777, 25455, 17236, 18043, 12598, 24418, 26996, 29535, 26990, 29556, 13108, 25695, 28518, 24376, 24421, 14128, 13154, 13368, 13949]
# Up to 0 to 126 because of pairs of characters.
for val in enc_dec:
for i in range(127):
if 0 <= (val - (i << 8)) <= 126:
print(chr(i) + chr(val - (i * 256)), end='', flush=True)
# OR
decoded_chars = ''.join([
chr(i) + chr(val - (i << 8))
for val in enc_dec
for i in range(127)
if 0 <= (val - (i << 8)) <= 126
])
enc = "灩捯䍔䙻ㄶ形楴獟楮獴㌴摟潦弸彥ㄴㅡて㝽"
output, output2 = "", ""
for i in range(len(enc)):
output += chr(ord(enc[i])>>8)
output += chr(ord(enc[i]) - ((ord(enc[i])>>8)<<8))
two_byte_char_code = ord(enc[i])
upper_byte_char_code = ord(enc[i])>>8
upper_byte_isolated_char_code = (ord(enc[i])>>8)<<8 # The shifting to the left zeros out the lower byte.
lower_byte_char_code = ord(enc[i]) - ((ord(enc[i])>>8)<<8)
# Alternatively convert to string and then split the string binary representation.
two_byte_char_code_in_bin = bin(two_byte_char_code)[2:].zfill(16)
upper_byte_char_code1 = two_byte_char_code_in_bin[0:8]
lower_byte_char_code1 = two_byte_char_code_in_bin[8:16]
#print(int('01110000', 2))
#print(upper_byte_char_code1, lower_byte_char_code1)
#print(chr(int(upper_byte_char_code1, 2)) , chr(int(lower_byte_char_code1, 2)))
output2 += chr(int(upper_byte_char_code1, 2)) + chr(int(lower_byte_char_code1, 2))
print(bin(two_byte_char_code), bin(upper_byte_char_code), bin(upper_byte_isolated_char_code), bin(lower_byte_char_code))
#print(two_byte_char_code, upper_byte_char_code, upper_byte_isolated_char_code, lower_byte_char_code)
#print(chr(upper_byte_char_code), chr(lower_byte_char_code))
#output += chr(ord(enc[i]) - ((ord(enc[i])//256)*256))
#output += chr(ord(enc[i]) & 0xFF)
print(output)
print(output2)
decoded = ''.join([chr((ord(enc[i]) >> 8) & 0xFF) + chr(ord(enc[i]) & 0xFF) for i in range(0, len(enc), 2)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment