Created
August 2, 2019 15:41
-
-
Save DeadPackets/4859ce122d0f89ad07e734923abcc288 to your computer and use it in GitHub Desktop.
A script I wrote to solve a telephone CTF challenge.
This file contains hidden or 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
/* | |
Challenge Description: | |
Have you ever used an old-keypad mobile phone? | |
(Check out the image file) | |
7 -----> 7 | |
E -----> 333 | |
T -----> 88 | |
The flag is the numeral sum of the code in the text file. | |
"AGENT007" -----> 22.44.333.666.88.0.0.7 -----> 2+2+4+4+3+3+3+6+6+6+8+8+0+0+7 = 62 | |
NOTE: You only have 3 attempts to solve this challenge, so use them carefully. | |
Hint: It is recommended to write a script to finish this task accurately. | |
*/ | |
const fs = require('fs'); | |
let array = fs.readFileSync('./challenge_code.txt').toString().split(""); | |
let sum = 0; | |
const dictionary = { | |
1: "1", | |
2: "2ABC", | |
3: "3DEF", | |
4: "4GHI", | |
5: "5JKL", | |
6: "6MNO", | |
7: "7PQRS", | |
8: "8TUV", | |
9: "9WXYZ", | |
0: "0" | |
} | |
const keyArray = Object.values(dictionary); | |
const valueArray = Object.keys(dictionary); | |
for (let i = 0; i < array.length; i++) { | |
//First, we find out which key it is on | |
for (let y = 0; y < keyArray.length; y++) { | |
if (keyArray[y].indexOf(array[i].toUpperCase()) >= 0) { | |
//We found out which key it belongs to! | |
sum += parseInt(valueArray[y]) + parseInt(valueArray[y] * keyArray[y].indexOf(array[i].toUpperCase())); | |
break; //Stop loop | |
} | |
} | |
} | |
//Tada! | |
console.log(sum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment