Increment Nonce by any fixed value in loop
Afficher commentaires plus anciens
I have the nonce value in hex. Let say:
nonce = {'00' '11' '22' '33' '44' '55'};
I need to add any fixed value 'x'(hex) to this value in loop and need to save every new value.
I was doing this like:
nonce = {'00' '11' '22' '33' '44' '55'};
for i=1:5
nonce(i) = nonce + 01;
i = i+1;
end
But I am not acheiving what I need.
1 commentaire
Jan
le 25 Juin 2019
Please mention, what you expect as output. Having only not running code does not clarify, what you want to achieve.
Your code contains some bugs:
for i=1:5
nonce(i) = nonce + 01;
% Here on the left side there is a scalar cell element, and on
% the right you try to add 01 (which is the same as 1) to a
% cell vector.
i = i+1; % i is iterated by the FOR loop already
% so do not increase it manually
end
Réponse acceptée
Plus de réponses (1)
nonce = {'00' '11' '22' '33' '44' '55'};
toAdd = hex2dec('01');
for k = 1:5
nonce{k} = dec2hex(hex2dec(nonce{k}) + toAdd);
end
It might be easier to work with a double vector, if you want to perform calculations. Then hex strings are rather inefficient.
Catégories
En savoir plus sur Encryption / Cryptography dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!