How can a function receive data randomly or generate random data as entry?

12 Ansichten (letzte 30 Tage)
HI. I am looking for a function which I can enter data randomly or create a random data as a entry.
I work on text steganography in picture with MATLAB. I hope you can help me.
  11 Kommentare
wafa suresh
wafa suresh am 5 Jul. 2021
Thank you so much for this example, I will test.
Scott MacKenzie
Scott MacKenzie am 5 Jul. 2021
Bearbeitet: Scott MacKenzie am 6 Jul. 2021
For what it's worth, here's something I put together to demonstrate @Walter Roberson's comment on "pairs of letters" -- that the message will look more natural if each letter is selected considering its probability of following the previous letter. Indeed, the output looks more natural (i.e., more like English).
df = readcell('digram.txt'); % digrams+frequencies, sorted by digram
n = size(df,1); % 27x27 = 729
letters = cellfun(@(x) x(1), df(1:27:length(df(:,1)),1));
letterFreq = (sum(reshape(cell2mat(df(:,2)), 27, [])))';
csLetterFreq = [1; cumsum(letterFreq)];
diagrams = char(df(:,1));
diagramFreq = cell2mat(df(:,2));
csDigramFreq = cumsum([ones(1,27); reshape(cell2mat(df(:,2)),27,[])]);
tot = sum(letterFreq); % total frequency (~300 million)
% create random message (begin with random letter selected as per letter freq)
message(1) = letters(find(randi(tot) <= csLetterFreq, 1));
for i=2:100
idx1 = find(message(i-1) == letters); % previous letter idx
idx2 = find(randi(csDigramFreq(end,idx1)) <= csDigramFreq(:,idx1), 1) - 1; % next letter idx
message(i) = letters(idx2);
end
message = strrep(message, '_', ' ') % replace underscore with space
message = 'aghesthif be ngole tthef is s y ms jup citoses in in winomaledwethe osther h e bams sthe he corithon'

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by