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

sha-512

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

Best Answer

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.