# How do we change the positions of the elements of t matrix ?

1 view (last 30 days)
Arshub on 31 Dec 2021
Edited: Arshub on 1 Jan 2022
I need to use S as index to change positions of mateix A
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7]
C = 1:numel(ِِA);
S = unique(S,'stable');
S = [S C(~ismember(C,S))]
A =[111 222 30 4;
50 65 70 83;
10 27 39 40 ;
54 67 72 81 ]
I need to permutate positions of elements of matrix by bellow subistitute:
Substitute A(S(i) ) with A (S(M×N)−i+1).,where M and N is rows and cols of matrix
Here i = 1, 2,..., M × N/2
Note: this way for permutation from this paper:A novel plaintext-related image encryption scheme using hyper-chaotic system
I attached the part of permutation from algorithim in img step1: I reshap matrix to vector
[row,col]=size(A);
len=row*col;
B=reshape(A,1,len);
A=B;
step2: Substitute A(S(i) ) with A (S(M×N)−i+1).,where M and N is rows and cols of matrix
Here i = 1, 2,..., M × N/2
for i =1:len/2
A(S(i))=A(S(len-i+1));
end
Ab=reshape(A,row,col);
AA=reshape(Ab,1,len);
I get this result after permutation A by S:
Ab =
81 222 30 222
50 30 70 50
67 40 72 40
70 67 72 81
Then i need to make reverse operation to get back the original matrix.
for i =1:len/2
AA(S(len-i+1))=AA(S(i));
end
Abb=reshape(AA,row,col);
I get this result
Abb =
81 222 30 222
50 30 70 50
67 40 72 40
70 67 72 81
but I couldn't get the original matrix "A"
A= 111 222 30 4
50 65 70 83
10 27 39 40
54 67 72 81
What should I do to get original matrix from permutated matrix?
Note: it is immportant to me use this method to permutate matrix: "Substitute A(S(i )) with A (S(M×N)−i+1)."
I get this result instead of original matrix A:
Abb =
81 222 30 222
50 30 70 50
67 40 72 40
70 67 72 81
--------------------------------------------my code-----------------------------
A =[111 222 30 4;50 65 70 83; 10 27 39 40 ; 54 67 72 81 ];% original matrix we need to permutate
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7];% index used to permutate matrix A
%{
Remove the repeated elements from matrix index S, and
then put the absent numbers at the end to generate a new sequence X.
%}
C = 1:numel(A);
S = unique(S,'stable');
S = [S C(~ismember(C,S))]
% start permutation
[row,col]=size(A);
len=row*col;
B=reshape(A,1,len);
A=B;
for i =1:8
A(S(i))=A(S(len-i+1));
end
Ab=reshape(A,row,col);
% To get original matrix
AA=reshape(Ab,1,len);
for i =1:8
%encrimg1(m1)=im1_reshap(ind1(m1));%permutation
AA(S(len-i+1))=AA(S(i));
end
Abb=reshape(AA,row,col);
Arshub on 1 Jan 2022
the rest of the paper goes to diffusion phase after this permutation phase .
each phase indepentent each anther.

R2014a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!