// SIN Permutations What my script does is tests range of valid SINs and returns the valid ones, and if someone had the time and space, they could create a list of all possible SIN numbers. I do how ever, placed a GNU/GPL copyright placing ownership of the script. As well, any mis-use of the script, blah blah blah, I am not to be held responsible... * Version: 1.1 ************************************************************************* * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * The Free Software Foundation, Inc. * 59 Temple Place - Suite 330 * Boston, MA 02111-1307 USA *************************************************************************/ $gen_string = ''; $gen_string_first = '000000000'; $gen_string_last = '000000500'; $gen_string_final = ''; //set_time_limit(0); /* Define all varibles before using them within global! Good Habit to get into. Now, obviously if you are going to be going threw large numbers of SINs, you'll need to tell PHP to set the time limit to infinity. I do not reconnmend any SIN returns larger then 1 million at a time! With this script, you are able to change the return to enter into a database, or write directly to a file, or colelct into an array of some sort to calculate all the possible variations. */ function str_compare($digit) { /* The purpose of this function was to compare $digit from the loop below to the $compare_string below. The purpose of this is to create the last digit before it becomes $string. Its pretty much a mathematical solution to comparing a random number to $compare_string. */ $compare_string = '121212121'; $string = ''; for ($i = '0'; $i <= '8'; $i++) { if ($digit{$i} * $compare_string{$i} >= '10') { $ii = $digit{$i} * $compare_string{$i}; settype($ii, "string"); $string .= $ii{0} + $ii{1}; } else { $string .= $digit{$i} * $compare_string{$i}; } } return $string; } function str_validate($string) { /* The purpose of this function was to obtain the string from the previous function str_compare() and confirm wether or not the $digit is a valid Canadian SIN. */ settype($string, "string"); $string = $string{0} + $string{1} + $string{2} + $string{3} + $string{4} + $string{5} + $string{6} + $string{7} + $string{8}; if (preg_match("/^[0-9][0]$/", $string)) { return true; } else { return false; } } /* This loop illustrates a number generator, simply designed to create a digit from 0 - 999999999. It's to test every possible variation number possible in the range above. */ for ($gen_string = $gen_string_first; $gen_string <= $gen_string_last; $gen_string++) { if (strlen($gen_string) <= '1') { $gen_string = '00000000' . $gen_string; } elseif (strlen($gen_string) <= '2') { $gen_string = '0000000' . $gen_string; } elseif (strlen($gen_string) <= '3') { $gen_string = '000000' . $gen_string; } elseif (strlen($gen_string) <= '4') { $gen_string = '00000' . $gen_string; } elseif (strlen($gen_string) <= '5') { $gen_string = '0000' . $gen_string; } elseif (strlen($gen_string) <= '6') { $gen_string = '000' . $gen_string; } elseif (strlen($gen_string) <= '7') { $gen_string = '00' . $gen_string; } elseif (strlen($gen_string) <= '8') { $gen_string = '0' . $gen_string; } elseif (strlen($gen_string) <= '9') { $gen_string = $gen_string;} else { die('Too many values returned. Caustringg an error!'); } /* Since PHP does not handle numbers aswell as perl, the code above is to replace any missing 0's infront of the string, by concatenate the variables. Since all values must exist. Technically, 0 is not a valid string, I have left it accessible to the possibility of its use of it in the future. I also believe in finishing my statments, so I added extra elseif/else. They won't affect anything, but atleast it'll clearly stand out as an effort to kill the script if the values do go any larger. */ settype($gen_string, "string"); if (str_validate(str_compare($gen_string)) == true) { /* The purpose here is to return valid SIN numbers, with the example below, we see that it'll return to the client that requested it. Now for a return to a file as in a fwrite, you will need the following lines: $collected_sins.db = file('collected_sins.db', "a"); fwrite($collected_sins.db, $gen_string . "\n"); fclose(collected_sins.db); Do not forget to place the variable before the loop, and fclose after the loop. This is VERY IMPORTANT! Or you will have your file open/close for every string in the loop, and not just the ones valid. And place the fwrite here. */ echo $gen_string . "\n"; } } /* It is very possible to use a form to request the range, and choice set of methods of collectiong your data. But to keep this sweet and simple... well, you know what I mean. */ ?> ~Daemon 2005-12-05