Should this work?
1 2
|
unsigned long long int msglength;
char message_length[8] = {'(char)msglength'}
|
They have the same amount of bits. It compiles, but I don't think I'm getting the results I expected. Here is what I'm trying to do.
I'm trying to teach myself bit manipulation. To do this I am trying to write my own SHA-256 algorithm using criteria in FIPS PUB 180-4.
I'm getting stuck at the beginning with the padding. The padding needs to be a multiple of 512 bits. The format is like this
< x input bits >1< y zero bits >< 64 bits denoting the length of x >
It seems that the most logical container for this is a character array.
The part that stumps me the most is the last 64 bits. I thought I came up with an easy way to do it, but I don't think it works. Since I basically just need a 64 bit number, my idea was this. why can't I just store the length in an unsigned long long int and copy it to the last 8 bytes of the padding.
The reason I don't think it works, well this is what I tried.
1 2 3
|
unsigned long long int msglength = 5;
char message_length[8] = {'(char)msglength'}
cout << message_length[7] <<endl;
|
since 5 only requires 8 bits I expected that container to be holding the value of 5, or "00000101", I would think the others would be all zero. Instead It prints nothing to the screen. Could someone tell me the error of my ways :)