From the course: Symmetric Cryptography Essential Training

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Building a hash algorithm

Solution: Building a hash algorithm

(upbeat music) - [Tutor] So how'd that go? This is my solution for the chapter one challenge. In this source code I've added a few cout commands to print intermediate states and some general debugging information that might be helpful in visualizing what's happening. So uncomment, those of you'd like to see more of what's going on without running it through debugger. So starting from the top, I have some variables that help me handle padding. NewSize is the length of the input after it's been padded, toPad is the number of bytes of padding that have been added and paddedPlaintext is a copy of the input with the padding added. The state variable is going to be our internal state, and then later the value we return. But it starts as the initialization vector I already provided. I start by checking to see if the length of the input fits neatly as a multiple of eight bytes. If it does, we don't need to pad, otherwise we do. The padding part, which is here, figures out how much to pad…

Contents