-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_lrs.py
75 lines (70 loc) · 2.37 KB
/
analysis_lrs.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
# анализ сгенерированной последовательности ЛРП
import numpy as np
class AnalysisLRS:
def __init__(self, k, L):
self.k = k
self.data = list()
with open("result.txt", "r") as file:
self.data = file.read()
self.data = self.data.split(" ")[0:L]
self.data = [int(i) for i in self.data]
@staticmethod
def __to_list(data):
return [int(i) for i in bin(data)[2:]][::-1]
@staticmethod
def __from_list(data):
val = 0
for i in range(0, len(data) - 1):
val += data[i]
val *= 2
val += data[-1]
return val
def calculate_Berle_Kemp(self):
m, l, N = list(), list(), int()
m.append(1)
l.append(0)
if len(self.data) % 2 == 1:
N = 2 * self.k + 1
else:
N = 2 * self.k
for t in range(N):
m_t = self.__to_list(m[t])[::-1]
e_t = self.data[t]
for i in range(1, l[t] + 1):
if i >= len(m_t):
break
e_t ^= m_t[i] * self.data[t - i]
if e_t == 1:
lam = -1
while lam <= t - 1:
if l[lam + 1] >= l[t]:
break
lam += 1
m_lam = 1
if lam >= 0:
m_lam = m[lam]
m_lam = self.__to_list(m_lam)[::-1]
deg = t - lam
for j in range(0, deg):
m_lam.insert(0, 0)
for j in range(0, len(m_t)):
if j >= len(m_lam):
m_lam.append(m_t[j])
continue
m_lam[j] ^= m_t[j]
m.append(self.__from_list(m_lam))
elif e_t == 0:
m.append(m[t])
if e_t == 1 and l[t] <= t / 2:
l.append(t + 1 - l[t])
else:
l.append(l[t])
degree = l[-1]
polynom = self.__to_list(m[-1])[::-1]
print("\tАлгоритм Берликэмпа-Мэсси")
print("Минимальный многочлен: ")
for i in range(0, len(polynom) - 1):
if polynom[i] != 0:
print("x^{} + ".format(degree), end="")
degree -= 1
print("{}".format(polynom[-1]))