Created
February 10, 2018 00:53
-
-
Save k3rni/212ca3100345b6b9f844ffad13df8963 to your computer and use it in GitHub Desktop.
Decipher contents of a Hollerith-style punched card
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
# As read on the card, top-down. For convenience, leading zeros can be skipped | |
rows = [ | |
"11000001100001001110010101010101001011000110", | |
"11000000110000000101010001000100100100001", | |
"100011000110001000000100000000000001000", | |
"100001000000000000000100001001000000", | |
"0", | |
"100001000100101110110100000000100001000", | |
"10010000000000000000000000000000000", | |
"10001000000001000001000010000100000100011", | |
"1001000000100000000000000000000000010000000", | |
"0", | |
"1000000011101011100000000000000100100", | |
"10000000000000000010000001001001000000000000", | |
] | |
maxlen = max(len(row) for row in rows) | |
# Restore leading zeros | |
rows = ["0" * (maxlen - len(row)) + row for row in rows] | |
# Transpose: each column is a (badly named as it doesn't have exactly 8 bits) "octet" | |
octets = list(zip(*rows)) | |
# Convert back to list of strings, MSB (highest bit is first) | |
bitstrings = ["".join(bits) for bits in octets] | |
# Source: http://www.columbia.edu/cu/computinghistory/026.html plus some educated guessing | |
hollerith = { | |
0: ' ', | |
0x842: '.', 0x242: ',', | |
0x812: '(', 0x412: ')', | |
0x200: '0', 0x100: '1', 0x080: '2', 0x040: '3', 0x020: '4', 0x010: '5', | |
0x008: '6', 0x004: '7', 0x002: '8', 0x001: '9', | |
0x900: 'A', 0x880: 'B', 0x840: 'C', 0x820: 'D', 0x810: 'E', 0x808: 'F', 0x804: 'G', 0x802: 'H', 0x801: 'I', | |
0x500: 'J', 0x480: 'K', 0x440: 'L', 0x420: 'M', 0x410: 'N', 0x408: 'O', 0x404: 'P', 0x402: 'Q', 0x401: 'R', | |
0x280: 'S', 0x240: 'T', 0x220: 'U', 0x210: 'V', 0x208: 'W', 0x204: 'X', 0x202: 'Y', 0x201: 'Z', | |
} | |
# Convert octets to integers | |
values = [int(bitstring, 2) for bitstring in bitstrings] | |
# Print any unknown values and their positions | |
for i, v in enumerate(values): | |
if v not in hollerith: | |
print("{}:{}".format(i, hex(v))) | |
# Decode the card | |
print("".join(hollerith.get(b, '?') for b in values)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment