From e4e231880413c58215130c4b084ac49a03c16b9b Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 8 Nov 2018 19:01:10 +0900 Subject: Break out noise.c and packet_interface.c --- hexnoise.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'hexnoise.py') diff --git a/hexnoise.py b/hexnoise.py index b092bb3..e8a3d73 100755 --- a/hexnoise.py +++ b/hexnoise.py @@ -9,12 +9,12 @@ def _print_line(write, ts, line, width=16): h,m,s,ms = int(ts//3600), int((ts//60)%60), int(ts%60), int((ts%1.0) * 1000) timestamp = f'{h: 3d}:{m:02d}:{s:02d}:{ms:03d}' line = list(line) + [None]*(width-len(line)) - hexcol = '\033[94m' + hexcol = '\033[0m' col = lambda b, s: s if b != 0 else f'\033[91m{s}{hexcol}' hexfmt = ' '.join( ' '.join(col(b, f'{b:02x}') if b is not None else ' ' for b in line[i*8:i*8+8]) for i in range(1 + (len(line)-1)//8)) - asciifmt = ''.join(chr(c) if c is not None and chr(c) in string.printable else '.' for c in line) + asciifmt = ''.join(chr(c) if c is not None and chr(c) in string.printable and c>=0x20 else '.' for c in line) write(f'\033[38;5;244m{timestamp} {hexcol}{hexfmt} \033[38;5;244m|\033[92m{asciifmt}\033[38;5;244m|\033[0m', flush=True, end='') startup = time.time() @@ -29,9 +29,9 @@ def hexdump(write, packet, width=16): write() def send_packet(ser, data, width=16): - encoded = cobs.encode(data) + b'\0' print(f'\033[93mSending {len(data)} bytes\033[0m') - hexdump(print, encoded, width) + hexdump(print, data, width) + encoded = cobs.encode(data) + b'\0' ser.write(encoded) ser.flushOutput() @@ -67,7 +67,7 @@ if __name__ == '__main__': proto.set_as_initiator() proto.set_keypair_from_private_bytes(Keypair.STATIC, STATIC_LOCAL) proto.start_handshake() - print('\033[91mHandshake started\033[0m') + print('Handshake started') while True: if proto.handshake_finished: -- cgit