matlab code for pseudo random
조회 수: 5 (최근 30일)
이전 댓글 표시
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));
댓글 수: 0
답변 (1개)
Rik
2020년 12월 8일
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
Rik
2020년 12월 8일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!