Web Analytics

Technically Impossible

Lets look at the weak link in your statement. Anything "Technically Impossible" basically means we haven't figured out how yet.

{'\"?!}, {mrdoc} and {gtaio luSnemf} - 42 SILICON VALLEY Piscine 2017 Day01 Exercise 09

日本人向け

恐らく検索結果に飛びついて、何も周りを見ていないのだろう。
日本のユーザーは誰も下記ページのExercise 09を参照しようとしない。
impsbl.hatenablog.jp

Abstract

Piscine is the admission test of 42 SILICON VALLEY, and is held for straight 4 weeks. Piscine Day 01 (the 2nd day because of starting at 0) Exercise 9 requests to turn in one shell script called "add_chelou.sh". Its requirement is

Write a command line that takes numbers from variables FT_NBR1, in ’\"?! base, and FT_NBR2, in mrdoc base, and displays the sum of both in gtaio luSnemf base.

Example 1

FT_NBR1=\'?"\"'\
FT_NBR2=rcrdmddd

The sum is : Salut

Example 2

FT_NBR1=\"\"!\"\"!\"\"!\"\"!\"\"!\"\"
FT_NBR2=dcrcmcmooododmrrrmorcmcrmomo

The sum is : Segmentation fault

Although this is the part of the entrance test, it is the kind of encryption decoding question in CTF (Capture The Flag) rather than an exam item. Hint for solution is not provided.

This post explains its solution.


If this question should be rephrased, it will be


3 strings below indicaded in [] should be interpreted as base-N numeral system. N is the length of string.

  1. [’\"?!]
  2. [mrdoc]
  3. [gtaio luSnemf]

Define 2 string variables based on #1 and 2 above, and find the sum of both. Decoding this sum with #3 above, it leads following outputs.

FT_NBR1=\'?"\"'\
FT_NBR2=rcrdmddd
FT_NBR1 + FT_NBR2 = Salut

FT_NBR1=\"\"!\"\"!\"\"!\"\"!\"\"!\"\"
FT_NBR2=dcrcmcmooododmrrrmorcmcrmomo
FT_NBR1 + FT_NBR2 = Segmentation fault

Write a command line for this process.

Both FT_NBR1 and 2 has 5 characters. It means they are different expression of base-5 numeral system. And [gtaio luSnemf] is the expression of base-13 numeral system.
Defining them with commands for converting numeral system, they will be

FT_NBR1 sed "s/'/0/g" | tr '\\"?!' 1234
FT_NBR2 tr mrdoc 01234
gtaio luSnemf tr 0123456789ABC 'gtaio luSnemf'

FT_NBR1 and 2 is base-5 numeral system, and their sum is also base-5 numeral system. Decoding this sum in base-13 numeral system can be defined as

xargs echo 'obase=13; ibase=5;' | bc | tr 0123456789ABC 'gtaio luSnemf'

Requested shell "add_chelou.sh" is
gist.github.com

Avoiding character escaping as possible, NT_NBR1 and 2 in Example 1 can be defined as

str1="\'?"
str2='"\"'
str3="'"
str4='\'
FT_NBR1=$str1$str2$str3$str4
FT_NBR2="rcrdmddd"

Execute this commands with FT_NBR1 and 2, it outputs "Salut".

str1="\'?"
str2='"\"'
str3="'"
str4='\'
FT_NBR1=$str1$str2$str3$str4
FT_NBR2="rcrdmddd"

echo $FT_NBR1 + $FT_NBR2 | sed "s/'/0/g" | tr '\\"?!' 1234 | tr mrdoc 01234 | xargs echo 'obase=13; ibase=5;' | bc | tr 0123456789ABC 'gtaio luSnemf'