Skip to content

Commit 91c27e6

Browse files
Commit my current codebase
1 parent cdf01af commit 91c27e6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

noise.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import random
2+
class Noise:
3+
def __init__(self):
4+
self.alpha = list("qwertyuiopasdfghjklzxcvbnm")
5+
def encode(self, string):
6+
const = []
7+
for s in list(string):
8+
sin = random.randint(0, 4)
9+
for i in range(5):
10+
if i == sin:
11+
const.append(s)
12+
else:
13+
cap = random.randint(0, 2)
14+
if cap == 0:
15+
const.append(random.choice(self.alpha))
16+
else:
17+
const.append((random.choice(self.alpha)).upper())
18+
const.append(str(sin))
19+
return "".join(const)
20+
21+
def decode(self, string: str) -> str:
22+
table = []
23+
for c in string:
24+
try:
25+
ic = int(c)
26+
except:
27+
continue
28+
else:
29+
table.append(ic)
30+
for i in range(6):
31+
string = string.replace(str(i), "|")
32+
broken_string = string.split("|")
33+
broken_string.pop((len(broken_string)-1))
34+
const = []
35+
counter = 0
36+
for segment in broken_string:
37+
const.append(segment[table[counter]])
38+
counter += 1
39+
return "".join(const)

0 commit comments

Comments
 (0)