-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDecodeMain.py
More file actions
86 lines (53 loc) · 1.75 KB
/
DecodeMain.py
File metadata and controls
86 lines (53 loc) · 1.75 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import BinaryDecode
import KeyDecode
import KeyGenerator
def ReArrangeBit(BinaryKeyTable, OrderedKeyHash):
BinaryString = ['0', '0', '0', '0']
i = 0
n = 0
while not n > 3:
i = 0
while not i > 3:
if OrderedKeyHash[i] == n:
BinaryString[n] = BinaryKeyTable[i]
i = i + 1
n = n + 1
return BinaryString
def RetrieveBinaryTable(NumberList, Key):
UBinTable = BinaryDecode.BinaryList(NumberList)
UOrderList = KeyDecode.OrderByKeyList(Key)
UOrderKey = KeyDecode.OrderKey(Key, UOrderList)
OrderKey = KeyDecode.FlipDictionary(UOrderKey)
BinaryStrList = ReArrangeBit(UBinTable, OrderKey)
BinaryString = StickTogether(BinaryStrList)
return BinaryString
def StickTogether(binarystrlist):
return "".join(binarystrlist)
def flip(x):
if x == 0:
return 1
if x == 1:
return 0
def FlipBits(binary,key):
msgBinary = binary
BitKey = key
msgBinaryList = list(msgBinary)
keyList = list(BitKey)
numRange = range(0,16)
for x in numRange:
keyList[x] = int(keyList[x],16)
for x in keyList:
a = msgBinaryList[int(x)]
b = flip(int(a))
msgBinaryList[int(x)] = str(b)
return msgBinaryList
def Decrypt(NumberList, key):
BinString = RetrieveBinaryTable(NumberList, key)
KeyString = "".join(KeyGenerator.ConvertToList(key))
bitlist = FlipBits(BinString, KeyString)
string1 = "".join(bitlist[0:8])
string2 = "".join(bitlist[8:16])
char1 = chr(int(string1, 2))
char2 = chr(int(string2, 2))
charstring = char1 + char2
return charstring