-
Notifications
You must be signed in to change notification settings - Fork 3
/
FindLFSRkeyExample.m
116 lines (85 loc) · 2.26 KB
/
FindLFSRkeyExample.m
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
clear all
close all
rng(254)
Aleng = 60;
for i =1:Aleng
A{i} = randi([0 1]);
end
numOfmessages =121;
[z,~] =LFSR1(A,numOfmessages);
for i =1:numOfmessages
m{i} = randi([0 1]);
c{i}= xor(z{i},m{i});
end
index=1;
disp('start')
index=index+1;
setIndex =1;
compA=truth_table(setIndex);
tic
for j =1:length(compA(:,1))
for i=1:setIndex
testA{i} = logicalZonotope.enclosePoints(compA(j,i));
tempA{i} = compA(j,i);
end
% try first the chosen bits and other are logical zonotope
for i=setIndex+1:Aleng
testA{i} = logicalZonotope.enclosePoints([0 1]);
end
[testz,~] =LFSR1(testA,numOfmessages);
for i =1:numOfmessages
testc{i}= xor(testz{i},logicalZonotope.enclosePoints(m{i}));
end
flagChosenBits =0;
for i =1:numOfmessages
if ~testc{i}.containsPoint(c{i})
flagChosenBits =1;
break;
end
end
if flagChosenBits ==1
% do not continue with chosen bits
continue;
end
% the chosen bits are correct, let's continue
for kk=setIndex+1:Aleng
testA{kk} = logicalZonotope.enclosePoints([0]);
for i=kk+1:Aleng
testA{i} = logicalZonotope.enclosePoints([0 1]);
end
[testz,~] =LFSR1(testA,numOfmessages);
for i =1:numOfmessages
testc{i}= xor(testz{i},logicalZonotope.enclosePoints(m{i}));
end
flag{kk} =0;
for i =1:numOfmessages
if ~testc{i}.containsPoint(c{i})
flag{kk} =1;
break;
end
end
for i=setIndex+1:kk
if flag{i}==1
testA{i} = logicalZonotope.enclosePoints([1]);
tempA{kk}=1;
else
testA{i} = logicalZonotope.enclosePoints([0]);
tempA{kk}=0;
end
end
end
sum=0;
for i =1:Aleng
sum = sum + abs(tempA{i}-A{i}) ;
end
sprintf("sum key =%d , j =%d ",sum,j)
%
% [testz2,~] =LFSR1(tempA,numOfmessages);
% sum2=0;
% for i =1:numOfmessages
% cRecover{i}= xor(testz2{i},m{i});
% sum2 = sum2 + abs(cRecover{i} - c{i});
% end
% sprintf("sum message =%d",sum2)
end
%execTime = toc