-
Notifications
You must be signed in to change notification settings - Fork 8
/
LinerBlockCode.py
79 lines (35 loc) · 1.18 KB
/
LinerBlockCode.py
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
#!/usr/bin/env python
#-*- codingLutf-8 -*-
class LinerBlock:
def __init__(self,codeLength,check,array,vectorM):
self.codeLength = codeLength
self.check = check
self.array = array
self.vectorM = vectorM
def CreateArray(self,array):
array = array.split(' ')
step = len(array)/self.codeLength
return [array[i*self.codeLength:(i+1)*self.codeLength] for i in range(step)]
def Multiply(self,arrayM,arrayG):
returnResutl = ''
for i in range(len(arrayG[0])):
colArray = [array[i] for array in arrayG]
returnResutl += str(sum([int(x)*int(y) for x,y in zip(colArray,arrayM)])%2)
return returnResutl
def Encode(self):
self.array = self.CreateArray(self.array)
self.vectorM = self.vectorM.split()
return self.Multiply(self.vectorM,self.array)
def main():
# codeLength = 4
# check = 3
# array = '1 0 0 1 0 1 0 1 0 0 1 1'
# vectorM = '1 0 1'
codeLength = raw_input("Input length num:")
check = raw_input("Input check num:")
array = raw_input("Input array:")
vectorM = raw_input("Input m:")
linerBlock = LinerBlock(int(codeLength),int(check),array,vectorM)
print 'The code is:' + linerBlock.Encode()
if __name__ == '__main__':
main()