Last active
May 14, 2022 02:29
-
-
Save ph1ee/4b97a505eb15d0bea3101bd7a7566008 to your computer and use it in GitHub Desktop.
a simple tool to generate and validate chargen stream
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
#!/usr/bin/env python3 | |
import sys | |
import time | |
from enum import Enum | |
asciistr = r"""!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}""" | |
class State(Enum): | |
LF = 1 | |
STR = 2 | |
if not sys.stdin.isatty(): | |
state = State.LF | |
offset = None | |
while True: | |
if state == State.LF: | |
s = sys.stdin.read(1) | |
if s == "\n": | |
state == State.STR | |
if state == State.STR: | |
s = sys.stdin.read(74) | |
if not offset: | |
offset = asciistr.index(s[0]) | |
if s[:72] != asciistr[offset : offset + 72] or s[-2:] != "\r\n": | |
sys.exit(1) | |
offset = asciistr.index(s[1]) | |
else: | |
time.sleep(0.1) # a short delay for counterpart to get ready to receive data | |
offset = 0 | |
while True: | |
print(f"{ asciistr[offset : offset + 72] }\r\n", end="") | |
offset = offset + 1 if offset < 92 else 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment