"Rainydays Sunshine" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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...



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

Reply via email to