Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
Arshub
Arshub el 31 de Dic. de 2021
Editada: Arshub el 1 de En. de 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);
  5 comentarios
DGM
DGM el 1 de En. de 2022
Editada: DGM el 1 de En. de 2022
Well okay, that's one step, but I don't see how this is supposed to be reversible.
A = [111 222 30 4; 50 65 70 83; 10 27 39 40; 54 67 72 81];
S = [1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7];
n = numel(A);
C = 1:n;
S = unique(S,'stable');
X = [S C(~ismember(C,S))];
% forward transformation
% vectorization/loops aren't necessary here
k = 1:n/2; % assumes n is even
Ab = A;
Ab(X(k)) = Ab(X(n-k+1))
Ab = 4×4
81 222 30 222 50 30 70 50 67 40 72 40 70 67 72 81
% the mapping from A to Ab retains only half of the members of A
% making the process irreversible
numel(unique(A))
ans = 16
numel(unique(Ab))
ans = 8
% for clarity, these are the map indices of the subsets:
k
k = 1×8
1 2 3 4 5 6 7 8
n-k+1
ans = 1×8
16 15 14 13 12 11 10 9
I don't know what the rest of the book/paper suggests beforehand or afterward, but I don't see how this is supposed to be reversible unless we're both making incorrect assumptions about the process. What's the rest of the book say?
Arshub
Arshub el 1 de En. de 2022
Editada: Arshub el 1 de En. de 2022
the rest of the paper goes to diffusion phase after this permutation phase .
each phase indepentent each anther.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by