Skip to content

Instantly share code, notes, and snippets.

@michsiw96
Last active August 23, 2023 18:26
Show Gist options
  • Save michsiw96/14b1e60ae2e93137ec4cde61e99c7309 to your computer and use it in GitHub Desktop.
Save michsiw96/14b1e60ae2e93137ec4cde61e99c7309 to your computer and use it in GitHub Desktop.
from PIL import ImageSequence, Image
import string, binascii, base64
colors = []
for i in range(6):
im = Image.open('flag' + str(i + 1) + '.gif')
colors.append([])
try:
while True:
new_frame = im.convert('RGB')
colors[i].append(new_frame.getdata()[0])
im.seek(im.tell()+1)
except EOFError:
pass
for i in range(6):
colors[i] = [x for (x, j, k) in colors[i]]
print ('flag' + str(i + 1) + '.gif:', colors[i])
print ()
guessed_mapping = {3: '0', 5: '1'}
print ('flag1.gif encoded:', "".join([guessed_mapping[i] for i in colors[0]]))
flag1 = int("".join([guessed_mapping[i] for i in colors[0]]), 2)
flag1 = flag1.to_bytes((flag1.bit_length() + 7) // 8, 'big').decode()
print ('flag1.gif decoded:', flag1 + '\n')
strips = []
gifs = ['1st.gif', '2nd.gif', '3rd.gif', '4th.gif']
for i, name in enumerate(gifs):
im = Image.open(name)
strips.append([])
for j in range(0, 500, 20):
frame = im.convert('RGB')
strips[i].append(frame.getdata()[j])
strips[i] = [x for (x, j, k) in strips[i]]
print (name + ':', strips[i])
print ()
pallette = sum(strips, [])
colors = [map(pallette.index, i) for i in colors]
colors = [list(i) for i in colors]
for i in range(6):
print ('flag' + str(i + 1) + '.gif:', colors[i])
print ()
def map_to_alphabet(alphabet, list):
return ''.join([alphabet[i] for i in list])
digits = string.digits
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
b8 = map_to_alphabet(digits, colors[1])
print ('flag2.gif encoded:', b8)
b8 = [b8[i:i+3] for i in range(0, len(b8), 3)]
flag2 = ''.join(list(map(lambda x: chr(int(x, 8)), b8)))
print ('flag2.gif decoded:', flag2 + '\n')
print ('flag3.gif encoded:', map_to_alphabet(digits, colors[2]))
flag3 = str(binascii.unhexlify(map_to_alphabet(digits, colors[2])))[2:-1]
print ('flag3.gif decoded:', flag3 + '\n')
flag4 = map_to_alphabet(uppercase + digits[2:8] + '=', colors[3])
print ('flag4.gif encoded:', flag4)
flag4 = str(base64.b32decode(flag4))[2:-1]
print ('flag4.gif decoded:', flag4 + '\n')
flag5 = map_to_alphabet(uppercase + lowercase + digits + '+/=', colors[4])
print ('flag5.gif encoded:', flag5)
flag5 = str(base64.b64decode(flag5))[2:-1]
print ('flag5.gif decoded:', flag5 + '\n')
flag6 = map_to_alphabet(digits + uppercase + lowercase + '!#$%&()*+-;<=>?@^_`{|}~', colors[5])
print ('flag6.gif encoded:', flag6)
flag6 = str(base64.a85decode(flag6, adobe=True))[2:-1]
print ('flag6.gif decoded:', flag6 + '\n')
flag = '3DS{' + flag1 + flag2 + flag3 + flag4 + flag5 + flag6 + '}'
print ('The flag is:', flag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment