forked from DCRasPi/RasPi-Encryption
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryDecode.py
More file actions
70 lines (42 loc) · 1.55 KB
/
BinaryDecode.py
File metadata and controls
70 lines (42 loc) · 1.55 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
#This contains all the functions relating to the binary decoding of a file
def splitString(numberString):
tempString = str(numberString)
outStringPiv0 = numberString[:4]
outStringPiv1 = numberString[4:]
outString0 = outStringPiv0[:2]
outString1 = outStringPiv0[2:]
outString2 = outStringPiv1[:2]
outString3 = outStringPiv1[2:]
outIntString0 = int(outString0)
outIntString1 = int(outString1)
outIntString2 = int(outString2)
outIntString3 = int(outString3)
outList = []
outList.append(outIntString0)
outList.append(outIntString1)
outList.append(outIntString2)
outList.append(outIntString3)
return outList
def BinaryList(numericlist):
binarylist = []
binarylist.append(RetrieveBits(numericlist[0]))
binarylist.append(RetrieveBits(numericlist[1]))
binarylist.append(RetrieveBits(numericlist[2]))
binarylist.append(RetrieveBits(numericlist[3]))
return binarylist
def RetrieveBits(integer):
binarystring = bin(integer)[2:]
binarylist = list(binarystring)
while len(binarylist) < 4:
binarylist.insert(0, '0')
binarystring = "".join(binarylist)
return binarystring
def GetBitDict(binary):
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 GetBitString(binarylist):
return "".join(binarylist)