Azzera filtri
Azzera filtri

matlab code for pseudo random

4 visualizzazioni (ultimi 30 giorni)
marie lasz
marie lasz il 8 Dic 2020
Commentato: Rik il 8 Dic 2020
hello,
Maybe I am asking a very dumb question here but I would like to confirm if I am thinking it right or not. this code is generating some pseudo random noise (please correct me if I am wrong) , so the question is what is this _key.bmp image file , I mean any grayscale image can I read here? I know by this file we are actually generating a key here, so what can be alternate solution here maybe?
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
rand('state',key);
% generate PN sequence
pn_sequence_zero=round(2*(rand(1,sum(sum(midband)))-0.5));

Risposte (1)

Rik
Rik il 8 Dic 2020
This looks like a fairly fragile setup to share an encryption key.
Any file that results in a valid state value can be used. By setting the state you make the next calls to random functions return predictable output. So if I use the same state on my copy of the same release of Matlab I will get the same results as you.
  2 Commenti
marie lasz
marie lasz il 8 Dic 2020
so is it better to add any key rather than adding file and that key we can use in returning the same random sequence?
Rik
Rik il 8 Dic 2020
The file is the key. My point is only that you are relying on the random number generator being the exact same between two users. If you're only using it for an example that would be fine, but if you're actually using it for something important you should either use a completely different setup, or make sure you're using the exact same release-update combination.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by