Skip to content

Instantly share code, notes, and snippets.

@00xc

00xc/solve.py Secret

Last active February 24, 2021 14:49
Show Gist options
  • Save 00xc/ef410c5a79615eed8d0c7140e95e2068 to your computer and use it in GitHub Desktop.
Save 00xc/ef410c5a79615eed8d0c7140e95e2068 to your computer and use it in GitHub Desktop.
Tenable CTF 2021 - Hacker Manifesto
# Takes a group of 3 bytes and parses it into an offset, length and character
class Group:
def __init__(self, b):
self.off = ((b[1] & 0b11) << 8) | b[0]
self.num = b[1] >> 2
self.ch = chr(b[2])
# Yields lst in chunks of size n
def get_chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]
def out_to_string(data):
return "".join(o.ch for o in data)
if __name__ == '__main__':
with open("hacker_manifesto.txt", "rb") as f:
data = f.read()
# Parse the bytes into groups of 3
data = [Group(chunk) for chunk in get_chunks(data, 3)]
# Iterate through the groups
out = []
for i, group in enumerate(data):
if group.off == 0 and group.num == 0:
out.append(group)
else:
start = -group.off
end = start + group.num
# We need this check because out[-n:0] does not work as expected (out[-n:0] != out[-n:])
if end == 0:
out += out[start:]
else:
out += out[start:end]
out.append(group)
print(out_to_string(out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment