Home CTFs | 404CTF_2023 | Programmation | Des mots, des mots, des mots
Post
Cancel

CTFs | 404CTF_2023 | Programmation | Des mots, des mots, des mots

Des mots, des mots, des mots

image

In this challenge, we need to access a netcat server and create a code that will respect the different rules stated:

image

The rule 0 is an example. It just ask us to send back the same string. So, because we have cosette, we send cosette.

image

For the rule 1, we need to reverse all the characters. So cosette become ettesoc.

image

For the rule 2, if the word has an even number of letters, swap the 1st and 2nd parts of the resulting word. Otherwise, remove all the letters in the word corresponding to the central letter. We had ettesoc, so we now need to send ttsoc because the length of the word is odd, then we remove the letter e that is at the center of the word.

image

For the 3rd rule, if the word has 3 or more letters, then if the 3rd letter of the resulting word is a consonant, “shift” the vowels to the left in the original word, then reapply rules 1 and 2. Otherwise: same thing, but shift them to the right. If the word has less than 3 letters we just return the word. This “shift” just means that we need to move only the vowels. The consonant doesn’t change position. The example is poteau that become petauo after the left shift. As you can see, the p is still the first letter and the t is still the 3rd letter. Only vowels have moved. So ttsoc become ottsc.

image

The 4th rule is the harder one. To explain it I will show and explain the code to solve it:

1
2
3
4
5
6
7
8
9
10
11
12
13
def regle4(mot):
	mot = list(mot)
	n = 0
	while n < len(mot):
		c = mot[n]
		# check if c == consonne
		if c.lower() not in voyelles and c.isalpha():
			vp = getVoyelle(c)
			s = mySomme(mot, n)
			a = ((vp + s) % 95) + 32
			mot.insert((n+1),chr(a))
		n += 1
	return "".join(mot)

Here, for each letter, we will check if it’s a vowel. If it is, we will do the calculation, if not we just pass. The calculation is a = ((vp + s) % 95) + 32. Where vp is the ASCII code of the vowel preceding the consonant c in the alphabet (if c = 'F', vp = ord('E') = 69). And s = SUM{i=n-1 -> 0}(a{i}*2^(n-i)*Id(l{i} is a vowel)), where a{i} is the ASCII code of the i-th letter of the word, Id(x) is 1 if x is true, 0 otherwise, and l{i} is the i-th letter of the word.

For more information about how I did the calculation of a, s and vp, you can find the hole code here

Now that we have a code that can translate a word, we automate that to translate the given text and we get the flag:

image

So the final flag is: 404CTF{:T]cdeikm_)W_doprsu_nt_;adei}

This post is licensed under CC BY 4.0 by the author.