2011-02-13 20:32:02 -05:00
|
|
|
import random
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
kbloc = [
|
|
|
|
[x for x in "1234567890-="],
|
|
|
|
[x for x in "qwertyuiop[]"],
|
|
|
|
[x for x in "asdfghjkl:;'"],
|
|
|
|
[x for x in "zxcvbnm,.>/?"],
|
|
|
|
]
|
2011-02-13 20:32:02 -05:00
|
|
|
kbdict = {}
|
2023-02-09 14:52:26 -05:00
|
|
|
for i, l in enumerate(kbloc):
|
|
|
|
for j, k in enumerate(l):
|
2011-02-13 20:32:02 -05:00
|
|
|
kbdict[k] = (i, j)
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
sounddict = {
|
|
|
|
"a": "e",
|
|
|
|
"b": "d",
|
|
|
|
"c": "k",
|
|
|
|
"d": "g",
|
|
|
|
"e": "eh",
|
|
|
|
"f": "ph",
|
|
|
|
"g": "j",
|
|
|
|
"h": "h",
|
|
|
|
"i": "ai",
|
|
|
|
"j": "ge",
|
|
|
|
"k": "c",
|
|
|
|
"l": "ll",
|
|
|
|
"m": "n",
|
|
|
|
"n": "m",
|
|
|
|
"o": "oa",
|
|
|
|
"p": "b",
|
|
|
|
"q": "kw",
|
|
|
|
"r": "ar",
|
|
|
|
"s": "ss",
|
|
|
|
"t": "d",
|
|
|
|
"u": "you",
|
|
|
|
"v": "w",
|
|
|
|
"w": "wn",
|
|
|
|
"x": "cks",
|
|
|
|
"y": "uy",
|
|
|
|
"z": "s",
|
|
|
|
}
|
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
|
|
|
|
def mispeller(word):
|
|
|
|
if len(word) <= 6:
|
|
|
|
num = 1
|
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
num = random.choice([1, 2])
|
2021-03-23 17:36:43 -04:00
|
|
|
wordseq = list(range(0, len(word)))
|
2011-02-13 20:32:02 -05:00
|
|
|
random.shuffle(wordseq)
|
|
|
|
letters = wordseq[0:num]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def mistype(string, i):
|
|
|
|
l = string[i]
|
2021-03-23 17:36:43 -04:00
|
|
|
if l not in kbdict:
|
2011-02-13 20:32:02 -05:00
|
|
|
return string
|
|
|
|
lpos = kbdict[l]
|
|
|
|
newpos = lpos
|
|
|
|
while newpos == lpos:
|
2022-10-07 16:51:40 -04:00
|
|
|
newpos = (
|
|
|
|
(lpos[0] + random.choice([-1, 0, 1])) % len(kbloc),
|
|
|
|
(lpos[1] + random.choice([-1, 0, 1])) % len(kbloc[0]),
|
|
|
|
)
|
|
|
|
string = string[0:i] + kbloc[newpos[0]][newpos[1]] + string[i + 1 :]
|
2011-02-13 20:32:02 -05:00
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def transpose(string, i):
|
2022-10-07 16:51:40 -04:00
|
|
|
j = (i + random.choice([-1, 1])) % len(string)
|
2011-02-13 20:32:02 -05:00
|
|
|
l = [c for c in string]
|
|
|
|
l[i], l[j] = l[j], l[i]
|
|
|
|
return "".join(l)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def randomletter(string, i):
|
2022-10-07 16:51:40 -04:00
|
|
|
string = (
|
|
|
|
string[0 : i + 1]
|
|
|
|
+ random.choice("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
+ string[i + 1 :]
|
|
|
|
)
|
2011-02-13 20:32:02 -05:00
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def randomreplace(string, i):
|
2022-10-07 16:51:40 -04:00
|
|
|
string = (
|
|
|
|
string[0:i] + random.choice("abcdefghijklmnopqrstuvwxyz") + string[i + 1 :]
|
|
|
|
)
|
2011-02-13 20:32:02 -05:00
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def soundalike(string, i):
|
|
|
|
try:
|
|
|
|
c = sounddict[string[i]]
|
|
|
|
except:
|
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
string = string[0:i] + c + string[i + 1 :]
|
2011-02-13 20:32:02 -05:00
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
|
|
|
|
func = random.choice([mistype, transpose, randomletter, randomreplace, soundalike])
|
2011-02-13 20:32:02 -05:00
|
|
|
for i in letters:
|
|
|
|
word = func(word, i)
|
|
|
|
return word
|