-
Notifications
You must be signed in to change notification settings - Fork 0
/
inverse_even.m
69 lines (46 loc) · 1.43 KB
/
inverse_even.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
function [P_Matrix] = inverse_even(k,Dimen)
for j=1:size(Dimen,2)
for i=1:size(Dimen,1)
X=dec2bin(i-1,log2(size(Dimen,1)));
Y=dec2bin(j-1,log2(size(Dimen,2)));
[X]=inverse_bit(X);
[Y]=inverse_bit(Y);
% Step 1
if Y(k+1)=='1' && X(k+1) == '0'
for m=1:k
Y(m)=xorbin(Y(m),Y(k+1));
X(m)=xorbin(X(m),Y(k+1));
end
end
% step 2
if X(k+1)=='1'
for m=k:-1:1
[Y(m),X(m)]=Swp(X(m),Y(m));
end
end
% step 3
if Y(k+1)=='1'
X(k+1)=xorbin(X(k+1),Y(k+1));
end
[X]=inverse_bit(X);
[Y]=inverse_bit(Y);
%%%%%%%%%
w= bin2dec(Y)+1;
l= bin2dec(X)+1;
P_Matrix(w ,l)=Dimen(j ,i);
end
end
end
function [output]=inverse_bit(input)
m=length(input);
output=dec2bin(0,m);
for n=1 : m
output(n)= input(m);
m=m-1;
end
end
function [B,A]=Swp(A,B)
t=A;
A=B;
B=t;
end