Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP crc32() only numbers

Tags:

php

crc32

I have a MD5 hash: 10f86782177490f2ac970b8dc4c51014

http://www.fileformat.info/tool/hash.htm?text=10f86782177490f2ac970b8dc4c51014 Result: c74e16d9

but PHP: crc32('10f86782177490f2ac970b8dc4c51014'); Result: -951183655

I don't understand!

like image 405
B11002 Avatar asked Mar 23 '10 11:03

B11002


People also ask

Is CRC32 faster than MD5?

If you want to check if two files are the same, CRC32 checksum is the way to go because it's faster than MD5. But be careful: CRC only reliably tells you if the binaries are different; it doesn't tell you if they're identical.

What does CRC32 return?

Returns a 32-bit Cyclic Redundancy Check (CRC32) value. Use CRC32 to find data transmission errors. You can also use CRC32 if you want to verify that data stored in a file has not been modified.

Is CRC32 a good hash?

CRC32 works very well as a hash algorithm. The whole point of a CRC is to hash a stream of bytes with as few collisions as possible. That said, there are a few points to consider: CRC's are not secure.

Can you reverse CRC32?

A CRC32 is only reversible if the original string is 4 bytes or less.


1 Answers

It's only a matter of representation of the data :

  • c74e16d9 is the hexadecimal representation
  • and -951183655 is the decimal representation.


And here's a portion of code to illustrate that :

$crc = crc32('10f86782177490f2ac970b8dc4c51014');
var_dump($crc);
var_dump(dechex($crc));

It'll display :

int -951183655
string 'c74e16d9' (length=8)

Which corresponds to :

  • The decimal representation of the value of your CRC
  • and, after that, the hexadecimal represenation of that same value.
like image 194
Pascal MARTIN Avatar answered Nov 08 '22 01:11

Pascal MARTIN