snakeCTF logo

this iS not PN

CRYPTO

Description

I'm a symmetric cryptography expert and I think permutation networks are always impossible to break, no matter what components are used.

Solution

Analysis

The user is provided with the encryption of the flag after 5 rounds and 6 rounds. Why? With 5 rounds the first half of the flag can be found, whilst the second half can be found by exploiting the 6 rounds ciphertext. The goal is to write the equations for both the instances and find some relations that can help to obtain the desired blocks.

The cipher

Given a key KK, each round of the cipher works as shown by the following image:

Cipher

Where, given a key kk, the function ff is defined as f(X,k)=Xsha1(k)f(X,k) = X \oplus \text{sha1}(k). For ease of notation, K=sha1(k)K = \text{sha1}(k).

The relations

From the 5 round instance:

C2(3)=T2(3)T2(4)C1T1(4)C_2^{(3)} = T_2^{(3)} \oplus T_2^{(4)} \oplus C_1 \oplus T_1^{(4)}

C2(2)=C2(3)T2(2)T1(3)C1C2T2(4)C_2^{(2)} = C_2^{(3)} \oplus T_2^{(2)} \oplus T_1^{(3)} \oplus C_1 \oplus C_2 \oplus T_2^{(4)}

P2=T2(1)T1(2)C2(3)T2(0)T1(1)P_2 = T_2^{(1)} \oplus T_1^{(2)} \oplus C_2^{(3)} \oplus T_2^{(0)} \oplus T_1^{(1)}

From the 6 round instance:

C2(4)=T2(4)T2(5)C1T1(5)C_2^{(4)} = T_2^{(4)} \oplus T_2^{(5)} \oplus C_1 \oplus T_1^{(5)}

C2(1)=T2(2)T1(3)C2(4)T2(1)T1(2)C_2^{(1)} = T_2^{(2)} \oplus T_1^{(3)} \oplus C_2^{(4)} \oplus T_2^{(1)} \oplus T_1^{(2)}

P1=C2(1)T1(0)P_1 = C_2^{(1)} \oplus T_1^{(0)}

Flag

The flag is the concatenation of P1P_1 and P2P_2.

Code

Here is the solver code.