Exercise in Master Padlock “Picking” meets PHP
After seeing:
http://lifehacker.com/5376442/crack-a-master-combination-padlock-redux
which has a link to a graphic art representation of how to pick a master padlock:
http://www.markedwardcampos.com/index.php?/design/master-lock/
a coworker and I set about to figure out the pattern in the tables that help you reduce the possible combinations from 64,000 to only 100 (to open the lock without knowing the combination).
Seeing the pattern, I wrote a quick piece of shoddy php to generate the combinations needed based on the number you divine from the mechanical part of the process.
<?
$num = $argv[1]; $mod = $num % 4; $secondRow[] = $mod % 2; if($mod > 1) $secondRow[] = $mod; $secondRow[] = $primer = 6 + $mod; $i = $mod; while($i < 40) { $firstRow[] = $i; $i += 4; } $i = $primer + 4; while($i < 40) { $secondRow[] = $i; $i += 4; } echo "\nStart with the first number of the top row, in combination with the first number of the second row\nThen use the same number of the top row with second number of the bottom row\nThis way you reduce the possibilities from 64,000 to only 100\n"; foreach($firstRow as $row){ echo $row . "\t"; } echo "\n|\\\t/|\\\t/|\\...\n"; foreach ($secondRow as $row){ echo $row . "\t"; } echo "\n\nLast number is: {$num}\n\n"; ?>
Sloppy but accurate.
Cheers