/solve.py Secret
Last active
February 24, 2021 14:49
Revisions
-
00xc revised this gist
Feb 24, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ # 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] -
00xc created this gist
Feb 24, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ class Group: def __init__(self, b): self.off = ((b[1] & 0b11) << 8) | b[0] self.num = b[1] >> 2 self.ch = chr(b[2]) 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))