-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmanipulate_CRC_computations.py
More file actions
40 lines (35 loc) · 960 Bytes
/
manipulate_CRC_computations.py
File metadata and controls
40 lines (35 loc) · 960 Bytes
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
#!/usr/bin/env python3
import itertools
import zlib
def comb_calc_bit(num):
tuples = list(itertools.product([0, 1], repeat=num))
res=[]
for elem in tuples:
elem = str(elem)[1:-1]
elem = "".join(elem.split(", "))
res.append(elem)
return res
def crc(message, div):
pad='0'*(len(div)-1)
message = message + pad
message = list(message)
div = list(div)
for i in range(len(message)-len(pad)):
if message[i] == '1':
for j in range(len(div)):
message[i+j] = str((int(message[i+j])^int(div[j])))
return ''.join(message[-len(pad):])
def calculate_all_collision(message,div,prefixList=None):
final_crc=crc(message,div)
comb5=comb_calc_bit(len(div))
curr_msg=""
res=[]
if prefixList==None:
prefixList=comb_calc_bit(len(message)-len(div))
for prefix in prefixList:
for calc_bit in comb5:
curr_msg=prefix+calc_bit
if crc(curr_msg,div) == final_crc:
res.append(curr_msg)
return res
print calculate_all_collision("11010110","10011",["111"])