Skip to content

Instantly share code, notes, and snippets.

@wonderb0lt
Created February 2, 2022 16:15
Show Gist options
  • Save wonderb0lt/55f57f045e426342bea4b14b5d91ba57 to your computer and use it in GitHub Desktop.
Save wonderb0lt/55f57f045e426342bea4b14b5d91ba57 to your computer and use it in GitHub Desktop.
Work at Dynatrace in Vienna, then you'll know ;)
import string
def read_single(chars = 0):
input_sequence = input(f'> ')
char = chr(int(input_sequence, base=2))
if char in string.printable:
return char
else:
raise Exception(f'Invalid character: binary sequence {input_sequence} is not a printable character')
def decode_once():
chars = []
while True:
try:
chars.append(read_single())
print(f'OK. {len(chars)} chars')
except EOFError:
break
except Exception as e:
print(f'''That din't work, try again (progress so far is saved): {str(e)}''')
result = ''.join(chars)
print(f'{len(chars)} characters read, and they mean:\n\t > {result} <')
def main():
print('''
Please enter the punch card string as a series of binary digits (e.g. " ·· ··" will become 01100001).
Once you're done, send EOF (Ctrl+D) to get the result. You can Ctrl+C at any time.
''')
decode_once()
print('Goodbye.')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment