-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdc.py
More file actions
68 lines (61 loc) · 2.68 KB
/
dc.py
File metadata and controls
68 lines (61 loc) · 2.68 KB
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
import json
class Decoder():
def __init__(self):
self.oldKey = input("Put in your key: ") #string
if len(self.oldKey) > 676:
print("Error, Invalid Key")
exit()
self.decodeKey()
self.createEncryption()
self.createCypher()
alphabet = ['@', '6', '"', '^', '!', 'Q', 'E', ')', 'U', 'X', '&', 'Y', 'G', 'o', '*', '{', 'l', 'x', '3', ';', "'", '8', 'N', '2', 'T', 'F', 's', '>', 'e', '-', 'k', ' ', '\\', '#', ':', '.', ']', 'g', '%', 'f', 'q', '4', '}', 'u', '$', 'T', 'z', '|', '(', '9', 'h', '1', 'Z', 'a', '7', 'R', '<', ',', 'K', '/', 'w', 'P', 'C', 'y', 'r', 'L', 'M', 'p', '0', '5', 'O', 'Q', 'n', 'c', '[', 'v', 'S', 't', '=', 'j', 'A', 'J', 'W', '_', 'D', 'I', 'b', 'i', 'B', 'd', 'V', 'm', '+', 'R', 'S', '~', 'H', '`', '?']
self.alphabet = alphabet
def decodeKey(self):
fixedKey = ""
for x in range(len(self.oldKey)):
a = self.oldKey[int(x)]
if a == '0':
fixedKey += "0"
elif a == '1':
fixedKey += "1"
else:
for y in range(int(self.oldKey[int(x)]) - 1): #4
fixedKey += self.oldKey[int(x) + 1]
self.key = fixedKey
def createEncryption(self): #creates a code from key
with open("config.json", "r") as f:
oec = json.load(f)["list"]
ec = []
for x in range(len(self.key)):
v = self.key[int(x)]
if v == "0":
if [oec[int(x)][0], oec[int(x)][1]] not in ec:
ec.append([oec[int(x)][0], oec[int(x)][1]])
else:
ec.append([oec[int(x)][1], oec[int(x)][0]])
elif v == "1":
if [oec[int(x)][1], oec[int(x)][0]] not in ec:
ec.append([oec[int(x)][1], oec[int(x)][0]])
else:
ec.append([oec[int(x)][0], oec[int(x)][1]])
self.ec = ec
def createCypher(self):
aligned = []
for x in range(len(self.ec)):
if x % 2 == 0:
aligned.append([self.ec[int(x)]] + [self.ec[int(x) + 1]])
self.aligned = aligned
def decode(self, phrase):
decrypted = ""
for x in range(len(phrase)):
if x % 2 == 0:
index = [phrase[int(x)], phrase[int(x) + 1]]
for y in range(len(self.aligned)):
if index in self.aligned[y]:
decrypted += self.alphabet[y]
break
return decrypted
dc = Decoder()
with open("encoded.ecdc", "r") as f:
phrase = f.read()
print(dc.decode(phrase))