Re: please help.. serial number generator

From: Date: Thu, 01 Aug 2002 19:01:48 +0000
Subject: Re: please help.. serial number generator
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-20954@lists.php.net to get a copy of this message
"Rainydays Sunshine" <rainydays_sunshine@hotmail.com> wrote in message news:20020730102035.39411.qmail@pb1.pair.com... > I need to create some kind of 10 digits serial number where I can generate > and check that it is valid. Sort of like a checksum.. How many unique values do you need, and how hard-to-fake? I would consider something like 7+3 digits - the first seven digits are generated more or less randomly, and the last three are checksums... this gives you 10 million valid combinations, and a one-in-a-thousand chance of any random number being valid. Obviously, the quickest way to increase security is to increase the number of digits. Each checksum can be any formula you can imagine, for example // Expects: // d (digits) - array [0..6] of integer in [0..9] function checksum1($d) { // scrambler array $s = array( 24, 78, 63, 501, 88, 89, 53, 14, 34, 266 ); return( ( ( $s[$d[0]] * $s[$d[6]] * 5) % 29 + ( $s[$d[1]] * $s[$d[5]] * 7) % 31 + ( $s[$d[2]] * $s[$d[1]] * 11) % 37 + ( $s[$d[3]] * $s[$d[2]] * 13) % 41 + ( $s[$d[4]] * $s[$d[0]] * 17) % 43 + ( $s[$d[5]] * $s[$d[4]] * 19) % 47 + ( $s[$d[6]] * $s[$d[3]] * 23) % 53 ) % 10 ); } Hope this helps...

« previous php.db (#20954) next »