### 2017-07-24

Learn to Open Master Locks.Master brand combination locks are widespread and not great. Here's a program to practice the mental math involved in cracking them. Use this information for good, not evil.

`#!/usr/bin/perl use strict; use warnings; # generate a Master-type combination my $first = int rand 40; my $third = ($first + 4 * int rand 10) % 40; # congruent to first mod 4 my $second = ($third + 2 + 4 * int (1 + rand 8)) % 40; # congruent to first+2 mod 4, not equal to third +- 2 # front disc is serrated so third number can't be found just by tensing shackle and turning dial my $true_gap = $third % 10; my $false_gap = ($third + 1 + int rand 9); # non-identical digit # give discoverable clues print "\n", "back disc rubs at ", ($first + 34) % 40, ".5\n", "front disc catches at ", join(' and ', sort {$a <=> $b} ($true_gap, $false_gap)), "\n\n"; # candidate thirds my %thirds = map {$_ => 1} grep { ($_ % 10 == $true_gap or $_ % 10 == $false_gap) and $_ % 4 == $first % 4 } 0..39; unless (exists $thirds{$third}) {print " this program is broken \n\n"; exit 1} # user silently calculates first number # user calculates candidate thirds while (scalar keys %thirds) { print "enter candidate for third number: "; my $cand = 0 + <STDIN>; if ($cand % 10 != $true_gap and $cand % 10 != $false_gap) { print "not congruent to a gap\n"; next } if ($cand % 4 != $first % 4) { print "not congruent to first number\n"; next } delete $thirds{$cand}; print "accepted\n"; } # user tries each candidate on the lock, under tension print "\nthat's all of them. $third has the most play\n\n"; # user must try up to eight possible second numbers print "you have eight guesses. enter each combo with whitespace between numbers"; for (1..8) { print "$_. "; $_ = <STDIN>; /(\d\d?)\s+(\d\d?)\s+(\d\d?)/ or next; # perl-haters, there's your line noise if ($1 == $first and $2 == $second and $3 == $third) { print "\nsuccess!\n\n"; exit 0 } } # how to fail print "\nsorry, you're out of time. the combination was $first $second $third.\n\n";`

22:14