-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyla.py
executable file
·140 lines (129 loc) · 4.42 KB
/
pyla.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
# Pielang
# Public domain
import sys, traceback
import re
def chop(thestring, ending):
if thestring.startswith(ending):
return thestring[len(ending):]
return thestring
def rchop(thestring, ending):
if thestring.endswith(ending):
return thestring[:-len(ending)]
return thestring
replacement_table = {"a": "ao",
"b": "c",
"c": "va",
"d": "t",
"e": "i",
"f": "g",
"g": "h",
"h": "y",
"i": "e",
"j": "k",
"k": "li",
"l": "p",
"m": "n",
"n": "m",
"o": "a",
"p": "q",
"q": "z",
"r": "sh",
"s": "ez",
"t": "d",
"u": "u",
"v": "w",
"w": "r",
"x": "j",
"y": "ie",
"z": "f"}
doubleReplace = {"hm": "hem",
"aao": "a",
"vaeao": "vayo",
"iee": "ie'e",
"ieau": "yao",
"hh": "h'h",
"tsh": "tash",
"csh": "cash",
"hup": "hurp",
"aomt": "ont",
"ryao": "rao",
"aoie": "ie",
"iao": "a",
"emg": "eng",
"dsh": "dish",
"yi": "ie",
"ii": "ie",
"uao": "ao",
"ziwi": "zwi",
"zdsh": "zdesh",
"zye": "zie",
"shsh": "sh",
"pez": "pz"}
badStarts = {"ez": "z",
"pao": "po",
"iau": "yao",
"iei": "ie",
"iee": "ie'e",
"ieao": "iao",
"qs": "meqs"}
badEndings = {"aop": "ao",
"pt": "t",
"dy": "die",
"hy": "hie"}
def decode(string):
nstring = string.split()
brf = []
for string in nstring:
lstring = list(string)
for index in range(0, len(lstring)):
char = lstring[index]
try: char2 = lstring[index-1]
except: char2 = ""
else:
if char2 != "e":
char2 = ""
if char in replacement_table.keys():
lstring[index] = replacement_table[char].replace(char2, "")
elif char.lower() in replacement_table.keys():
lstring[index] = replacement_table[char.lower()].replace(char2, "").title()
lstring = "".join(lstring)
for key in doubleReplace.keys():
lstring = lstring.replace(key, doubleReplace[key])
for k in ("title", "upper"):
lstring = lstring.replace(eval("\"%s\".%s()" % (key, k)), eval("\"%s\".%s()" % (doubleReplace[key], k)))
for key in badEndings.keys():
if lstring.endswith(key) and len(lstring) > len(key):
lstring = lstring[:-len(key)] + badEndings[key]
for k in ("title", "upper"):
if lstring.endswith(eval("\"%s\".%s()" % (key, k))) and len(lstring) > len(key):
lstring = lstring[:-len(key)] + eval("\"%s\".%s()" % (badEndings[key], k))
for key in badStarts.keys():
if lstring.startswith(key) and len(lstring) > len(key):
lstring = badStarts[key] + lstring[len(key):]
for k in ("title", "upper"):
if lstring.startswith(eval("\"%s\".%s()" % (key, k))) and len(lstring) > len(key):
lstring = eval("\"%s\".%s()" % (badStarts[key], k)) + lstring[len(key):]
if lstring.endswith("i"):
lstring += "r"
elif lstring.endswith("I"):
lstring += "R"
if lstring == "E":
lstring = "Nie"
elif lstring == "aom":
lstring = "nek"
elif lstring == "Aom":
lstring = "Nek"
elif lstring == "aon":
lstring = "nem"
elif lstring == "Aon":
lstring = "Nem"
brf.append(lstring)
return " ".join(brf)
def main(argv=[]):
x = " ".join(argv)
if len(x) == 0:
x = input("Enter string here: ")
print(decode(x))
if __name__ == "__main__":
main(sys.argv[1::])