---
title: peaCTF 2019 (Round1) - [Crypto] Broken Keyboard (50pts)
author: Maltemo
tags: CTF, peaCTF, Crypto, ASCII
---
peaCTF 2019 (Round1) - [Crypto] Broken Keyboard (50pts)
===
Written by [Maltemo](https://twitter.com/Maltemo), member of team [SinHack](https://sinhack.blog/).
[TOC]
## Statement of the challenge
### Description
Help! My keyboard only types numbers!
### Encrypted file :lock:
The file attached was `enc.txt` and contained :
```=
112 101 97 67 84 70 123 52 115 99 49 49 105 115 99 48 48 108 125
```
## Analysis :mag:
Thanks to the challenge's description, we get some informations that those numbers come from a keyboard.
We can expect that those numbers corresponds to letters.
And what makes numbers correspond to letter in IT ?
:arrow_forward: ASCII Table :arrow_backward:
Here is a quick explanation of what is the ASCII Table :
:::info
>ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort.
Source : https://www.asciitable.com/
:::
## Solution :unlock:
At this point, many methods can solve the challenge. We could do it only manualy with the ASCII Table and the message, but I will do it with javascript language.
Why ? Because it is fast, and I :heartbeat: javascript !
First step consists in starting node in the console :
```=
node
```
:::warning
If you don't have nodejs installed on your laptop, you can still execute this code from the console of your own browser. Or you can install it on the [official website](https://nodejs.org/en/download/).
:::
Then we can write down some javascript, and everytime we will hit the `Enter` button, it will execute the written code.
First step will be to store the encoded string in a variable :
```javascript=
let stringEnc = "112 101 97 67 84 70 123 52 115 99 49 49 105 115 99 48 48 108 125";
```
Then, we want to get an array of those numbers :
```javascript=
let arrayEnc = stringEnc.split(" ")
```
`.split(" ")` will cut the string in little pieces every time he finds the given string in parameter (here a space)
Now, we have an array of strings of encoded characters.
```javascript=
console.log(arrayEnc);
//[ '112','101','97','67','84','70','123','52','115',
//'99','49','49','105','115','99','48','48','108','125' ]
```
But we want to have number to decode them back to characters.
So we are going to apply a function on every element of the array, with the `map()` function.
We convert the element from `String` to `Number` with `Number()`
And then we convert this number to the corresponding character in the ASCII table with `String.fromCharCode()`.
```javascript=
let arrayDec = arrayEnc.map(function(element){
return String.fromCharCode(Number(element));
});
```
Finaly, we are going to get back a single string from the array that now contains the letters of the flag.
`.join("")` function will do the trick.
It will create a string by concatenating every element and spliting them with the given string (here an empty one).
```javascript=
arrayDec.join("");
```
If we are in node console, it will display the code. In the browser too normaly.
But if not, you can still display the output with `console.log()` :
```javascript=
console.log(arrayDec.join(""));
```
### TL;DR
The numbers where numbers of the ASCII Table, that corresponds to letters.
:::success
One line solution in javascript :
```javascript=
"112 101 97 67 84 70 123 52 115 99 49 49 105 115 99 48 48 108 125".split(" ").map(elt => String.fromCharCode(Number(elt))).join("");
```
:::
### Flag :white_check_mark:
The flag is : **peaCTF{4sc11isc00l}**
___
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License</a>.