Last active
April 30, 2017 18:09
-
-
Save guyellis/9942e16d1f3daf79d9b89e4128a07ec2 to your computer and use it in GitHub Desktop.
Generate combinations for a Master Combo Padlock after a reset went wrong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// After resetting the Master Combo Lock I was unable to unlock it. | |
// Assuming that I had been off on one or more on the new number/ | |
// letters I needed to generate all of the combinations so I could | |
// open it. | |
// This is an example of the combo I thought I set it to: | |
const combo = '0AT'; | |
// These are the numbers/letters available on the dial: | |
const letters = '0123456789ADEHJLNRST'; | |
// Find a letter/number before a given letter/number | |
function before(letter) { | |
const index = letters.indexOf(letter); | |
if(index === 0) { | |
return letters[letters.length - 1]; | |
} | |
return letters[index - 1]; | |
} | |
// Find a letter/number after a given letter/number | |
function after(letter) { | |
const index = letters.indexOf(letter); | |
if(index === letters.length - 1) { | |
return letters[0]; | |
} | |
return letters[index + 1]; | |
} | |
// We need an array of three letter/number combinations | |
// with the letters/numbers falling on either side of the | |
// combo we thought we had set. | |
// In our example we need: | |
// [ [ 'T', '0', '1' ], [ '9', 'A', 'D' ], [ 'S', 'T', '0' ] ] | |
const combos = combo.split('').map(letter => { | |
return [ | |
before(letter), letter, after(letter) | |
] | |
}); | |
console.log(combos); | |
for(let i = 0; i < 3; i++) { | |
for(let j = 0; j < 3; j++) { | |
for(let k = 0; k < 3; k++) { | |
console.log(`${combos[0][i]}${combos[1][j]}${combos[2][k]}`); | |
} | |
} | |
} | |
/* | |
Example list of combos: | |
T9S | |
T9T | |
T90 | |
TAS | |
TAT | |
TA0 | |
TDS | |
TDT | |
TD0 | |
09S | |
09T | |
090 | |
0AS | |
0AT | |
0A0 | |
0DS | |
0DT | |
0D0 | |
19S | |
19T | |
190 | |
1AS | |
1AT | |
1A0 | |
1DS | |
1DT | |
1D0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment