How can I create a 16 round for loop in this problem?

% I need different "In" on every stage and key in each stage would be ciphertext of previous stage
clear all;
clc;
Key = randi([0,1],[1,4])
In1 = randi([0,1],[1,4])
Ciphertext1 = xor(Key,In1)
Key1 = Ciphertext1
In2 = randi([0,1],[1,4])
Ciphertext2 = xor(Key1,In2)
Key2 = Ciphertext2
In3 = randi([0,1],[1,4])
Ciphertext3 = xor(Key2,In3)
Key3 = Ciphertext3
In4 = randi([0,1],[1,4])
Ciphertext4 = xor(Key3,In4)
Key4 = Ciphertext4
In5 = randi([0,1],[1,4])
Ciphertext5 = xor(Key4,In5)
Key5 = Ciphertext5
In6 = randi([0,1],[1,4])
Ciphertext6 = xor(Key5,In6)
Key6 = Ciphertext6
In7 = randi([0,1],[1,4])
Ciphertext7 = xor(Key6,In7)
Key7 = Ciphertext7
In8 = randi([0,1],[1,4])
Ciphertext8 = xor(Key7,In8)
Key8 = Ciphertext8
In9 = randi([0,1],[1,4])
Ciphertext9 = xor(Key8,In9)
Key9 = Ciphertext9
In10 = randi([0,1],[1,4])
Ciphertext10 = xor(Key9,In10)
Key10 = Ciphertext10
In11 = randi([0,1],[1,4])
Ciphertext11 = xor(Key10,In11)
Key11 = Ciphertext11
In12 = randi([0,1],[1,4])
Ciphertext12 = xor(Key11,In12)
Key12 = Ciphertext12
In13 = randi([0,1],[1,4])
Ciphertext13 = xor(Key12,In13)
Key13 = Ciphertext13
In14 = randi([0,1],[1,4])
Ciphertext14 = xor(Key13,In14)
Key14 = Ciphertext14
In15 = randi([0,1],[1,4])
Ciphertext15 = xor(Key14,In15)
Key15 = Ciphertext15
In16 = randi([0,1],[1,4])
Ciphertext = xor(Key15,In16)

回答 (1 件)

the cyclist
the cyclist 2022 年 8 月 22 日
編集済み: the cyclist 2022 年 8 月 22 日

0 投票

Use a cell array to store the values:
for k = 1:16
Key{k} = randi([0,1],[1,4]);
In{k} = randi([0,1],[1,4]);
Ciphertext{k} = xor(Key{k},In{k});
end

1 件のコメント

Md. Atiqur Rahman
Md. Atiqur Rahman 2022 年 8 月 22 日
編集済み: Md. Atiqur Rahman 2022 年 8 月 22 日
thanks for fast reply. But, I need different "In" on every stage and key in each stage would be ciphertext of previous stage

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2018a

質問済み:

2022 年 8 月 22 日

編集済み:

2022 年 8 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by