Filter löschen
Filter löschen

How to apply S-box on input data?

8 Ansichten (letzte 30 Tage)
lilly lord
lilly lord am 25 Jun. 2022
Kommentiert: Voss am 27 Jun. 2022
Hello, I have an S-box and I want to pass few numbers through S-box
if x=0,1,2,3,4,5,6,7 then S-box(x)=0,1,3,6,7,4,5,2
A=0:7;
Sbox=[0,1,3,6,7,4,5,2];
X=de2bi(A,3,'left-msb');
U=[];
res=[];
w1=[];
for i=1:length(A)
U(i,:)=xor(X(i,:),X(2,:));
res=bi2de(U,'left-msb')'
end
s_out=[];
for i=1:8
s_out = sbox(res(i));% error in this line
end
res=[1,0,3,2,5,4,7,6];
Apply S-box on res. Desired outcome for S-box(1)=1, S-box(0)=0, S-box(3)=6, S-box(2)=3, S-box(5)=4, S-box(4)=7, S-box(7)=2 and S-box(6)=5

Akzeptierte Antwort

Voss
Voss am 25 Jun. 2022
Bearbeitet: Voss am 25 Jun. 2022
A=0:7;
Sbox=[0,1,3,6,7,4,5,2];
N = length(A);
X=de2bi(A,3,'left-msb');
U=[];
% res=[];
% w1=[];
for i=1:N
U(i,:)=xor(X(i,:),X(2,:));
% res=bi2de(U,'left-msb')'
end
res=bi2de(U,'left-msb')'; % calculate res once, for all U, after the loop
s_out=[];
for i=1:N
% s_out = sbox(res(i));% error in this line
s_out(i) = Sbox(res(i)+1); % - the variable is Sbox, not sbox (MATLAB is case-sensitive)
% - add 1 to res(i) to use as index into Sbox (res starts at 0, index start at 1)
% - assign the result to s_out(i), i.e., a single element of s_out
end
s_out
s_out = 1×8
1 0 6 3 4 7 2 5
  2 Kommentare
lilly lord
lilly lord am 27 Jun. 2022
Thank you very much sir
Voss
Voss am 27 Jun. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by