Created
July 26, 2021 09:43
-
-
Save Dobby233Liu/0f561240a918c3dc4f37c1a56e4951f2 to your computer and use it in GitHub Desktop.
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
import random | |
random.seed() | |
lettertable = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " | |
def rand_word(): | |
while True: | |
random.seed() | |
r = "" | |
len = random.randint(6, 12) | |
for _ in range(len): | |
r += rchr() | |
yield r | |
def rchr(): | |
random.seed() | |
return lettertable[random.randint(0,len(lettertable)-1)] | |
def chnarray(x): | |
return list(map(ord, list(x))) | |
def chnear(cc, arr=lettertable): | |
return min(chnarray(arr), key=lambda x: abs(x - cc)) | |
def garble(s): | |
r = "" | |
for x in s: | |
o = " " | |
random.seed() | |
dice = random.randint(0, 14) | |
if dice == 0: | |
o = rchr() | |
elif dice == 1: | |
o = rchr()+o | |
elif dice == 2: | |
o = chr(chnear(ord(x) - random.randint(0,1))) | |
elif dice == 3: | |
o = chr(chnear(ord(x) + random.randint(0,1))) | |
elif dice == 6: | |
o = o+rchr() | |
elif dice >= 4: | |
o = x | |
r += o | |
return r | |
def stroke(): | |
word = rand_word() | |
while True: | |
random.seed() | |
r = garble(next(word)) | |
random.seed() | |
r = garble(r) | |
random.seed() | |
random.seed() | |
if random.randint(0, 93) == 57: | |
r += garble(" ") | |
yield r | |
def main(): | |
import time, sys | |
try: | |
for x in stroke(): | |
try: | |
sys.stdout.write(x) | |
sys.stdout.flush() | |
time.sleep(0.01) | |
except KeyboardInterrupt: | |
sys.stdout.write('\n') | |
break | |
except KeyboardInterrupt: | |
sys.stdout.write('\n') | |
return | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment