def main():
    um = UniversalMachine(Path('codex.umz').read_bytes())

    password = rb'(\b.bb)(\v.vv)06FHPVboundvarHRAkp'
    output = um.run()
    for c in password:
        assert um.state == UniversalMachine.State.WAITING, um.state
        um.write_input(c)
        output += um.run()

    assert um.state == UniversalMachine.State.HALT

    end_of_preamble = b'follows colon:'
    m = output.find(end_of_preamble) + len(end_of_preamble)
    assert m != -1
    print(output[:m].decode('ascii'))

    Path('umix.umz').write_bytes(output[m:])
예제 #2
0
def run(um: UniversalMachine, *, umin: BaseReader, umout: BaseWriter):
    while True:
        # if um.state == UniversalMachine.State.ERROR:
        #     # TODO
        #     print(um.error_message)
        #     return

        if um.state == UniversalMachine.State.IDLE:
            out = um.run()
            for byte in out:
                umout.writebyte(byte)
            continue

        if um.state == UniversalMachine.State.HALT:
            return

        assert um.state == UniversalMachine.State.WAITING

        c = umin.readbyte()
        if c is None: return
        um.write_input(c)