Need to create a for loop for this problem

조회 수: 1 (최근 30일)
Md. Atiqur Rahman
Md. Atiqur Rahman 2022년 8월 23일
답변: KSSV 2022년 8월 23일
clear all;
clc;
Key = randi([0,1],[1,2048]);
%Key(randperm(size(Key,2)))
Plaintext = randi([0,1],[1,256])
%Dividing PLaintext into Left and Right part
L = Plaintext(1:128);
R = Plaintext(129:256);
%Round one
F1 = xor(R,Key(1:128));
C1 = xor(F1,L);
%Round two
F2 = xor(C1,Key(129:256));
C2 = xor(F2,R);
%Round three
F3 = xor(C2,Key(257:384));
C3 = xor(F3,C1);
%Round four
F4 = xor(C3,Key(385:512));
C4 = xor(F4,C2);
%Round five
F5 = xor(C4,Key(513:640));
C5 = xor(F5,C3);
%Round six
F6 = xor(C5,Key(641:768));
C6 = xor(F6,C4);
%Round seven
F7 = xor(C6,Key(769:896));
C7 = xor(F7,C5);
%Round eight
F8 = xor(C7,Key(897:1024));
C8 = xor(F8,C6);
%Round nine
F9 = xor(C8,Key(1025:1152));
C9 = xor(F9,C7);
%Round ten
F10 = xor(C9,Key(1153:1280));
C10 = xor(F10,C8);
%Round eleven
F11 = xor(C10,Key(1281:1408));
C11 = xor(F11,C9);
%Round twelve
F12 = xor(C11,Key(1409:1536));
C12 = xor(F12,C10);
%Round thirteen
F13 = xor(C12,Key(1537:1664));
C13 = xor(F13,C11);
%Round fourteen
F14 = xor(C13,Key(1665:1792));
C14 = xor(F14,C12);
%Round fifteen
F15 = xor(C14,Key(1793:1920));
C15 = xor(F15,C13);
%Round sixteen
F16 = xor(C15,Key(1921:2048));
C16 = xor(F16,C14);
%Output
Ciphertext = [C15,C16]

답변 (1개)

KSSV
KSSV 2022년 8월 23일
idx = (0:128:2048)' ;
I = [idx(1:end-1)+1 idx(2:end)] ;
for i = 1:size(I,1)
I(i,:)
end
ans = 1×2
1 128
ans = 1×2
129 256
ans = 1×2
257 384
ans = 1×2
385 512
ans = 1×2
513 640
ans = 1×2
641 768
ans = 1×2
769 896
ans = 1×2
897 1024
ans = 1×2
1025 1152
ans = 1×2
1153 1280
ans = 1×2
1281 1408
ans = 1×2
1409 1536
ans = 1×2
1537 1664
ans = 1×2
1665 1792
ans = 1×2
1793 1920
ans = 1×2
1921 2048

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by