I am designing SHA-512 algorithm, i am new 2 matlab..i dont know how to perform the padding operation...can anyone help me?

4 views (last 30 days)
this is my code
ui=input('enter the username:','s')
pwi=input('enter the password','s')
concate=strcat(ui,pwi)
fprintf('%d',concate)
str=dec2bin(concate,8)
n=numel(str)
length=mod(896,1024)
a=896-n
now i want to perform the padding operation ,i want 1 followed by 871 zeros. Plz help me

Accepted Answer

Walter Roberson
Walter Roberson on 16 Mar 2014
Edited: Walter Roberson on 16 Mar 2014
padarray = [ones(1,1), zeros(1,871)];
Why are you trying to fprintf() strings with a %d format? You can do it and it is meaningful in some situations, but I would like to check what benefit you see from doing it.
You should never use "length" as a variable name, as doing so interferes with the MATLAB length() routine.
Are you sure you want 871 zeroes? Shouldn't you be padding "str" to a 1024 length boundary? "str" varies in length; you determined the number of elements in it to be "n", so I am not sure why you want 871 zeroes instead of "enough more than n to reach a 1024 elements boundary". Or if it works on 896 characters at a time, the one would expect a mod() involving 896 as the second argument.
Watch out, your "str" is a 2D matrix not a vector.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!