one time pad plus randstream

2 ビュー (過去 30 日間)
Mi
Mi 2023 年 1 月 20 日
コメント済み: Les Beckham 2023 年 1 月 23 日
Hello Guys,
I need help for this question asap.
Implement a version of the character based One-Time Pad, that utilizes a random number generator chosen through RandStream.
clc;
clear all;
close all;
alph=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
b1=0:25;
keyword='famt';
code='ratn';
disp(keyword);
famt
disp(code);
ratn
for ii=1:length(keyword)
for jj=1:length(alph)
if keyword(ii)==alph(jj)
w1(ii)=b1(jj);
end
if code(ii)==alph(jj)
c1(ii)=b1(jj);
end
end
end
ncode=w1+c1;
for ii=1:length(ncode)
if(ncode(ii)>25)
ncode(ii)=ncode(ii)-26;
else
continue
end
end
display(ncode);
ncode = 1×4
22 0 5 6
for ii=1:length(ncode)
for jj=1:length(b1)
if ncode(ii)==b1(jj)
finalcode(ii)=alph(jj);
else
continue
end
end
end
disp(finalcode);
wafg
  7 件のコメント
Les Beckham
Les Beckham 2023 年 1 月 20 日
You need to get clarification on what portion of the algorithm is supposed to be randomized. Perhaps the code string is supposed to be randomly generated? Until that is clarified, there isn't really anything else we can do to help with this.
Mi
Mi 2023 年 1 月 20 日
if the code string is supposed to be randomly generated, then can you help me out with a code for this?

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

採用された回答

Les Beckham
Les Beckham 2023 年 1 月 20 日
Assuming that the random part of the algorithm is generating the code character vector as you said in one of your comments, something like this should do what you want.
Note that this is using RandStream as requested. It could be more easily and more simply done using randi directly without using RandStream.
s = RandStream('dsfmt19937'); % << arbitrarily chosen generator type; change as you wish (see doc link above)
r = randi(s, 26, [1 4]); % 4 integers between 1 and 26 using stream s
code = char(r + 'a'); % convert to letters of the alphabet
% Then use the simplified one-time pad algorithm I showed in my comment above
keyword='famt';
w1 = double(keyword - 'a');
c1 = double(code - 'a');
ncode = mod(w1+c1, 26)
ncode = 1×4
6 6 20 3
finalcode = char(ncode + 'a')
finalcode = 'ggud'
  2 件のコメント
Mi
Mi 2023 年 1 月 20 日
thank you so much
Les Beckham
Les Beckham 2023 年 1 月 23 日
You are quite welcome.
Could you please Accept the answer? Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by