-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrmbl.m
114 lines (71 loc) · 2.71 KB
/
scrmbl.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
114
%----------Scrambeling--------------------
%
%
%
%--------initialisation-------------------
%-----k is coordination of images------------
%-----actually k = wigth+heigth or is equal to 2n in 2^n * n^2 images
%----calculate k value in each image
% ------for all images , that is calculated its k value
function [Scrambeled_position]= scrmbl(imCvr)
tic;
disp('Please wait for Partitioning and Scrambeling ...');
[new_position]=Partition(0,imCvr); %function Partition(0), initialization.
Dim=size(imCvr);
%% Cnot gate ..............................
for j=2:2.0:Dim(2)
for i=1:2.0:Dim(1)
if mod(j,2) == 0 % even
% swap pair cells
t=new_position(j,i);
new_position(j,i)=new_position(j,i+1);
new_position(j,i+1)=t;
% swap pair cells
end
end
end
%% Cnot gate ................................
%-------Partitioning with Odd & Even%functions-----------------------------%
Dim=size(imCvr);
for i=1:log2(Dim(1))-1
if i < log2(Dim(1))-1
%% re partitioning ...
[P_Matrix]= P_Matrix(i,new_position); % 512 to 256 (Blocking ...)
[P_Matrix]=Partition(0,P_Matrix);
[new_position]= Reverse_P_Matrix(i,P_Matrix,Dim(1)); % 256 to 512
end
if mod(i,2)==1 % odd
% odd func
[new_position] = odd(i, new_position);
else %even
% even func
[new_position] = Even(i,new_position);
end
end
Scrambeled_position = new_position;
toc;
end
function [P_Matrix]= P_Matrix(k,new_position)
row=1;
col=1;
for j=1:(2^k):length(new_position)
for i=1:(2^k):length(new_position)
P_Matrix{col,row} = new_position(j:j+(2^k)-1,i:i+(2^k)-1);
row=row+1;
end
row=1;
col=col+1;
end
end
function [new_position]= Reverse_P_Matrix(k,P_Matrix,Dim)
row=1;
col=1;
for j=1:(2^k):Dim
for i=1:(2^k):Dim
new_position(j:j+(2^k)-1,i:i+(2^k)-1)=P_Matrix{col,row};
row=row+1;
end
row=1;
col=col+1;
end
end