Tags: crypto
Rating:
The problem presents a [chosen plaintext attack](https://en.wikipedia.org/wiki/Chosen-plaintext_attack) , we can just sent it the entire set of ascii printable characters and return the encrypted value for each character.
```
./the_encoder.out
Welcome to the encoder
Please give me a plain text of max 40 characters
0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
```
Using this we can write a short script to decode the encrypted message.
```python
plaintext = '0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
ciphertext =[1385,1386,1387,1388,1389,1390,1391,1392,1393,1394,1395,1396,1397,1398,1399,1400,1401,1402,1403,1404,1405,1406,1407,1408,1409,1410,1411,1412,1413,1414,1415,1416,1417,1418,1419,1420,1421,1422,1423,1424,1425,1426,1427,1428,1429,1430,1431,1432,1433,1434,1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452,1453,1454,1455,1456,1457,1458,1459,1460,1461,1462]
msg = [1412,1404,1421,1407,1460,1452,1386,1414,1449,1445,1388,1432,1388,1415,1436,1385,1405,1388,1451,1432,1386,1388,1388,1392,1462]
d = ''
for c in msg:
d = d+(plaintext[ciphertext.index(c)])
print(d)
```
Running this, we return the flag
``
python3 encoder.py
KCTF{s1Mpl3_3Nc0D3r_1337}
``