create Sbox for encryption
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Good day,
How can I convert a series of 64-bit to (16 decimal) vector to create sbox,
for example, I need the output like this ... sbox=[12 5 6 11 9 0 10 13 3 14 15 8 4 7 1 2];
key input as (64-bit binary)
I'm write the below code
function s_out=updatesbox(key)
sbox=[];
for i=1:4:64
sbox[] = bin2dec(key(i:i+3)+1);
end
thanks
0 Kommentare
Antworten (1)
Divyam
am 7 Nov. 2024
You should add input validation to your code to ensure that the key is a string of 64 characters. The offset used in the "bin2dec" function is unnecessary considering that it does not add any value to the crytogrpahic strength.
To solve the indexing problem, you can use direct indexing with to correctly place each decimal value in the "sbox" array.
function s_out = updatesbox(key)
% Ensure the key is a string of 64 characters
if length(key) ~= 64
error('Key must be a 64-bit binary string.');
end
sbox = zeros(1, 16); % Preallocate space for the S-box
for i = 1:4:64
% Convert 4-bit binary substring to decimal
decimal_value = bin2dec(key(i:i+3));
% Add 1 to the decimal value to match your desired output
sbox((i+3)/4) = decimal_value;
end
s_out = sbox;
end
% Sample 64-bit binary input
key = '1100101011110000101010111100110010101011110000101010111100110010';
% Call the updatesbox function
sbox_output = updatesbox(key);
% Display the resulting S-box
disp('Generated S-box:');
disp(sbox_output);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Encryption / Cryptography finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!