Here is the statement, where key is a string of 32 characters, and input is a string of unknown length entered by the user.
if length(input) == 0 || length(input) % 32:
input += key[:32-length(input)%32]
The purpose of this statement is to ensure that the input string is 32 bytes (or a multiple of 32), and if not, it will proceed to append the necessary number of bytes, taken from key.
I get that much, but what I don't understand is specifically how this statement works:
input += key[:32-length(input)%32]
What I do understand is that the first 32 characters of key are being examined (however, the key is only 32 bytes long, so that doesn't really matter). However, what gets subtracted, and from which end of the string? Say for example, the key is "Hamilton's awesome hash function" (which is 32 characters), and I need 5 characters to make 32, will I get "Hamil" or will I get "ction" from this statement?
I need to know this so I can recreate it in C++. I would compile and run the code given, but the whole program is just Python pseudocode.
This post has been edited by Midwest Product: 23 September 2012 - 10:05 PM

New Topic/Question
Reply




MultiQuote






|