forked from DCRasPi/RasPi-Encryption
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecryption.py
More file actions
114 lines (54 loc) · 1.9 KB
/
Decryption.py
File metadata and controls
114 lines (54 loc) · 1.9 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
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
import DecodeMain
def BinaryString(integer):
string = bin(integer)[2:]
def GetBitDict(binarystring):
binarylist = list(binarystring)
binarydict = {}
while len(binarylist) < 16:
binarylist.insert(0, '0')
binarystring = "".join(binarylist)
binarydict[0] = binarystring[0:4]
binarydict[1] = binarystring[4:8]
binarydict[2] = binarystring[8:12]
binarydict[3] = binarystring[12:16]
return binarydict
def PutItBackTogether(unordereddict, KeyOrder):
binaryreplaced = {}
binaryreplaced[0] = ''
binaryreplaced[1] = ''
binaryreplaced[2] = ''
binaryreplaced[3] = ''
i = 0
while not i > 3:
if KeyOrder[i] == 0:
binaryreplaced[0] = unordereddict[i]
if KeyOrder[i] == 1:
binaryreplaced[1] = unordereddict[i]
if KeyOrder[i] == 2:
binaryreplaced[2] = unordereddict[i]
if KeyOrder[i] == 3:
binaryreplaced[3] = unordereddict[i]
i = i + 1
return binaryreplaced
def UnChain(cipherlist):
truecipherlist = []
IV = 0
n = 0
while not n == len(cipherlist):
if n == 0:
truecipherlist.append((cipherlist[n] + IV))
else:
truecipherlist.append((cipherlist[n] - cipherlist[n-1])%16)
n = n + 1
numberlist = []
i = 0
while not (i+4) > len(truecipherlist):
numberlist.append(truecipherlist[i:(i+4)])
i = i + 4
return numberlist
def Decipher(cipherlist, Key):
cList = UnChain(cipherlist)
Plaintext = ""
for value in cList:
Plaintext = Plaintext + (DecodeMain.Decrypt(value, Key))
return Plaintext