Paste Search Dynamic
generate();
  1. <?php
  2. generate();
  3.  
  4.  
  5. // FUNCTION
  6. function generate()
  7. {
  8.        $digilist = "0123456789ABCDEFGHJKLMNPQRTUVWXY";
  9.        //now we generate a new random ID number using the substrings of the digitList string above
  10.        $three_chars = null;
  11.        $three_chars .= substr( $digilist, rand( 1, 9 ), 1 );
  12.        $three_chars .= substr( $digilist, rand( 10, 31 ), 1 );
  13.        $three_chars .= substr( $digilist, rand( 10, 31 ), 1 );
  14.  
  15.        for( $i = 22; $i < 100; $i++)
  16.        {
  17.            $id = $three_chars . $i;
  18.            $key = get_key( $id );
  19.            echo $id . ":" . $key . "\n";
  20.        }
  21. }
  22.  
  23. function get_key( $id )
  24. {
  25.        $digilist = "0123456789ABCDEFGHJKLMNPQRTUVWXY";
  26.        //ok so now we need to generate an MD5 hash of our ID
  27.        $hash = md5($id);
  28.  
  29.        //cycle through the hash 16 (length of key) times (in steps of 2 because each hex bytes is 2 digits long)
  30.        $i = 0;
  31.        $key = null;
  32.        for ($i; $i < 32; $i+=2)
  33.        {
  34.                //here we convert the next hex value to an integer and perform a bitwise AND operation against '31'
  35.                //31 is the highest substring value in our digit list.
  36.                $nextdigit = hexdec(substr($hash, $i, 2)) & 31;
  37.  
  38.                //if 'i' is divisable by 8 (every 4 cycles) then we want to add "-"
  39.                if ((($i % 8) == 0) && ($i > 0))
  40.                {
  41.                        $key .= "-".substr($digilist, $nextdigit, 1);
  42.                }
  43.                else
  44.                {
  45.                        $key .= substr($digilist, $nextdigit, 1);
  46.                }
  47.        }
  48.        return $key;
  49. }
  50.  
  51. ?>
Parsed in 0.031 seconds