フィルターのクリア

How to apply S-box on input data?

8 ビュー (過去 30 日間)
lilly lord
lilly lord 2022 年 6 月 25 日
コメント済み: Voss 2022 年 6 月 27 日
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

採用された回答

Voss
Voss 2022 年 6 月 25 日
編集済み: Voss 2022 年 6 月 25 日
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 件のコメント
lilly lord
lilly lord 2022 年 6 月 27 日
Thank you very much sir
Voss
Voss 2022 年 6 月 27 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by