What are my md5 bits?

I am trying to code the md5 hash function in Python, but it does not work. I highlighted the problem for message bits that should be hashed. Yes, I actually convert every byte to bit and form a message bit (I want to learn the algorithm at the bit level). And this is where things fall apart; my bit string is malformed.

The simplest message will be ", 0 bytes long, padding will be" 1 "followed by (or not) 511" 0 "(the last 64 bits indicate the length of the message, which, as already mentioned, is simply 0).

1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 billion

I feed 32-bit chunks of data into a conversion function at a time. I tried to manually place 1 in all positions in the first fragment, as well as in the last fragment (small end). Where should be "1"?

Thank.

Refresh . The correct position for the first 32-bit word passed into the conversion should be: 00000000000000000000000010000000which int(x,2)is equal 128, this mess is due to my A = rotL((A+F(B,C,D)+int(messageBits[0],2)+sinList[0]), s11)+Bconvert format using int()to interpret bit strings as integer data, it int()takes a binary code of binary format, so 100 ... . was a very large number.

+3
source share
1 answer

MD5 uses a convention with a large end at the bit level, and then based on bytes based on the low end.

. . 0 255; 128, 64, 32, 16, 8, 4, 2 1 ( "big-endian at bit level" ).

32- . 0 4294967295. ( "little-endian at byte level" ). , a, b, c d , + 256 * b + 65536 * c + 16777216 * d.

( 8). , . , "1" , , big-endian, 128 (0x80).

"1" , . , . , "1" , 511 "0", . , 128, 63 0. 32- , (M 0) 128, 15 (M 1 M 15) 0.

. MD5. , , 2 RFC 1321. ( ) .

+4

Source: https://habr.com/ru/post/1773616/


All Articles