Created
September 8, 2012 03:26
-
-
Save dicato/3671583 to your computer and use it in GitHub Desktop.
Bungie challenge decoder
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 characters
import binascii | |
# This is the original puzzle from the mail sack! | |
puzzle = """ | |
9B3E9D48B3A3C99D162D2A75E44FA14A0C3A9261C5873E6D0AB522D2A7 | |
0E4C59D0E2D0A5063CD83524C38332659A51684583522C499663CFAF26A | |
48A9222C39F366CF9D4294187524C38B067449916B45A5063C59F3A2D38 | |
33A25A8B4A7C5A7527D08B3AA488B26950A53E3D283369AE8F16745A506A | |
499D1E1CF89166499716A48934E3C59D169419932CC9A7068528B52A59A | |
F1664C5B1A7D59D122C4A106A548B4A7549F166D0993ECAE9F3AA488B1A | |
649A14E4C48AB21559D1E4C5934E74FA9667D5A552CD0930E0CC8B3A3C | |
99D162D2933A3C7A53EAD05D5E2D7A526A45A14A7C7A5066D3AF26A489F | |
56A4F9D169AE9F569508B3E84C8B127CE9F526499716A488B3AACD85169 | |
2EAF22CBFAF1664C5952445A5160D28B1E94583522D2591E9419D122D29 | |
D566C28B4A9D49F06850996634FA53EAD2AF26659874A0C6A8BA6C1B322 | |
0D0B33EAC4934E0C7A5162ACA11694391067438B667D5831E9458ABABC | |
883526C1A9522D2A7269D49106A538B5A2CE934E6CFA5160D78B4E7CD8 | |
B524419D3E745AF2664C8B5A2D293360C7933A2C9A94E2CC8D527C28AB | |
A0CE894E7ACAF161CF8916BC9A9220CDA1322D38B5A2CEA6B274FA93E7 | |
45A6BA3418751D50A53E3D283369D0830E5C5895E4D4914E2D68B3A9C1 | |
A5166CFA5160D78B4E7CD8B524419D424D491668529F1E9419B4EA48835 | |
20D0A132CCF9D169AEB51694F8B4DFD78B3262CAF169D4933265491267 | |
4BA9222D94F4A2C79F3E22EA14A2D4A9668419906A4185322AEAF163D283 | |
4284C8B5E4D4916A2D29F169C19932A488B524CD8ABA2D68B3A74FAEBA | |
CC5A6BA445A515743833ACCFAB422CFA1322D38B16A488B35FD2931E454 | |
9116945933AA48934E64F9D1EA45B151FD083569C5A93EA4197160CC9F3 | |
A3CC9F3E5AEA11694391067438B52449A7220D385162CE835E4CCB31E0C | |
D8526A419932A48934EA499B15FD78B3262CA13E649A722A489F4E2D491 | |
2674B933A3C383429AEB33EAC8835A2C19B426459D566C28B4A9D49F1A4 | |
CE88BA441AD169CF9B163559C869D48366441A142CAE""".replace('\n', '') | |
def chunks(s, n): | |
"""Produce `n`-character chunks from `s`.""" | |
for start in range(0, len(s), n): | |
yield s[start:start + n] | |
# After we have learned the hint from the PAX picture, we know we have to: | |
# "First convert the hexadecimal to binary. Then, regroup the bits into chunks equal to our favorite number. | |
# Finally, read as ASCII." | |
# This one liner takes the puzzle in hexadecimal form, converts it to binary in 7 bit chunks, and then | |
# converts those chunks into individual characters. It finally appends it all together in one human readable | |
# string! | |
paragraph = ''.join([binascii.unhexlify('%x' % int(c, 2)) for c in chunks(bin(int(puzzle, 16))[2:], 7)]) | |
print 'Decoded paragraph:\n%s\n' % paragraph | |
# Based on hints from TheMissingLink and the paragraph, we know numbers are important. | |
# But there are no numbers in the paragraph, so let's convert it back to hexadecimal | |
# and look for sevens and zeroes. | |
backtohex = binascii.hexlify(paragraph) | |
print 'Hexadecimal representation of the paragraph:\n%s\n' % backtohex | |
# We can loop through the hexadecimal looking for the sevens and zeroes, | |
# count them, and also create a string out of them. We know from TheMissingLink | |
# there should be 91 total. | |
counter = 0 | |
binary_string = '' | |
for c in backtohex: | |
if c == '7' or c == '0': | |
counter += 1 | |
binary_string += c | |
print 'Found %s sevens and zeroes!\n' % counter | |
# Since Bungie uses sevens instead of ones, we can replace the sevens with ones, and convert the resulting | |
# binary string to ASCII one character at a time. This produces the final answer, which is a link! | |
finalanswer = ''.join([binascii.unhexlify('%x' % int(c, 2)) for c in chunks(binary_string.replace('7', '1'), 7)]) | |
print 'The final answer: %s\n' % finalanswer |
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 characters
import Image | |
img = Image.open("PAX.png") | |
width, height = img.size | |
pixels = img.load() | |
all_pixels = [] | |
# Only the last 86 pixels on the last two rows are of importance | |
for x in range(width - 86, width): | |
for y in (368, 369): | |
cpixel = pixels[x, y] | |
all_pixels.append(cpixel) | |
solution = "" | |
for p in all_pixels[0::4]: | |
solution += chr(p[0]) + chr(p[1]) + chr(p[2]) | |
print solution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment