Re: Verification number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Emil Edeholt schreef:
Hi

Sorry if this is considered off topic. Please ignore the post in that case.

My site uses ten digit numbers as ID:s for our products. I would like the last digit to be a verification/check digit. I was just about to just make some simple function that would add the other values together into a one digit verification digit. But I thought maybe there are better or worse ways of doing this, since some algorithms probably produce a more even distribution of verification digits than others do. I.e. it would be a shame if I later on notice that half of my ID:s get 9 as verification.

if the checksum is merely 1 byte there will only be 256 variations - and
they are liable to be concentrated in a certain range of values.

I'm not sure if the code below is anything like along the right lines,
I used your post as an excuse to play wih pack/unpack - which I
don't fully grok - but I'm guessing you want to create a checksum from the
id and binary encode the value (then add it to the id to create the final
public id) so that you can later perform the check sum check

$a = "123456789";
$r = crc32($a);
$u = sprintf("%u", $r);
$l = pack("H*", $u);
$k = unpack("H*", $l);

var_dump($u, $l, $k[1]);

$i = $a.$l;
$b = substr($i, 0, 9);
$c = substr($i, 9);

var_dump( $i, $b, $c, ($c == pack("H*", sprintf("%u", crc32($b)))) );

I may be on the completely wrong track, I'm sure I'm missing something and at
the very least there is probably an endianess issue I'm not taking into account.

maybe someone smart can offer a correction :-)


Any ideas?

Regards Emil


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux