Skip to content

Instantly share code, notes, and snippets.

@alan-mushi
Last active April 20, 2016 20:54
Show Gist options
  • Save alan-mushi/19f77d1b5f6537c6af7611599e199d6f to your computer and use it in GitHub Desktop.
Save alan-mushi/19f77d1b5f6537c6af7611599e199d6f to your computer and use it in GitHub Desktop.
data = "010001110101111001100011011011100100100100111001010111100100011101000111001110010100011100111001010001110011100101000111001110010101111001100011011011100100100101101110010010010011100100110101010111100110001100111001001101010110111001001001011011100100100101000111010111100011100100110101011011100100100101011110011000110100011101011110001110010011010101011110011000110101111001100011010111100110001101000111010111100101111001100011011011100100100101000111010111100011100100110101010001110101111001101110010010010101111001100011010111100110001101101110010010010101111001100011010111100110001100111001001101010100011101011110010111100110001101011110011000110101111001100011010001110101111001000111010111100101111001100011011011100100100101101110010010010101111001100011"
bits = list(map(lambda x: x == "1", data))
res = 0
for idx in range(0, len(bits), 8):
b = bits[idx:idx+8]
stage1 = [
b[0], not b[2],
not b[2], not b[1],
b[0], b[1],
b[6], b[5],
not b[1], not b[7]
]
stage1_out = [
stage1[0] & stage1[1],
stage1[2] & stage1[3],
stage1[4] & stage1[5],
stage1[6] ^ stage1[7],
stage1[8] ^ stage1[9]
]
stage2 = [
stage1_out[0], not b[3],
stage1_out[1], not b[3],
stage1_out[2], not b[3],
not b[5], b[2],
b[2], stage1_out[4]
]
stage2_out = [
stage2[0] & stage2[1],
stage2[2] & stage2[3],
stage2[4] & stage2[5],
stage2[6] & stage2[7],
stage2[8] & stage2[9]
]
stage3 = [
stage2_out[0], not b[4],
stage2_out[1], not b[4],
stage2_out[2], not b[4],
stage2_out[3], stage1_out[3]
]
stage3_out = [
stage3[0] & stage3[1],
stage3[2] & stage3[3],
stage3[4] & stage3[5],
stage3[6] & stage3[7]
]
stage4_out = [
stage3_out[0] | stage3_out[1],
stage3_out[2] | stage3_out[3]
]
stage5_out = stage4_out[1] | stage2_out[4]
out = stage4_out[0] | stage5_out
res = (res << 1) | out
print("res = " + bytes.fromhex(hex(res)[2:]).decode('ascii') + " hex = " + hex(res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment