Krypton Level 6 → Level 7

The challenge involves a stream cipher that uses a repeating key and a weak "random" number.
cd /krypton/krypton6
ls -la
file *

There are the provided hints:

The README contains the challenge description as always.

And the encrypt binary which will encrypt any string we gave it using the keyfile.dat in the same directory.
Lets test it out:
python3 -c "print('A' * 137)" > /tmp/Caesar3/plaintext.txt
./encrypt6 /tmp/Caesar3/plaintext.txt /tmp/Caesar3/cipher.txt
cat /tmp/Caesar3/cipher.txt

As shown every 30 character, the cipher text will repeat it self:
EICTDGYIYZKTHNSIRFXYCPFUEOCKRN
EICTDGYIYZKTHNSIRFXYCPFUEOCKRN
EICTDGYIYZKTHNSIRFXYCPFUEOCKRN
EICTDGYIYZKTHNSIRFXYCPFUEOCKRN
EICTDGYIYZKTHNSIR
Also with other letter:

The same process, where for example the first A and B letters are shifted 4 bytes, where the second A and B are shifted 8 bytes, and the third ones are shifted 2 bytes, and so on.
Knowing that we can easily recover the correct password, using the same method.
We can get how many character a character has been shifted starting from the first one, and we will use the same length of the encrypted flag:
Cipher_Text = "PNUKLYLWRQKGKBE"
Encoded_As = "EICTDGYIYZKTHNSIRFXYCPFUEOCKRN"
List = []
for i in range(len(Cipher_Text)):
As = "A" * len(Cipher_Text)
List.append(ord(Encoded_As[i]) - ord(As[i]))
print(List)
vim script.py
cat script.py
python3 script.py

This list contains where each A is shifted depending on its place in the string up to the length of the cipher text.
We will use this list to subtract the cipher text for each character with its index place:
Cipher_Text = "PNUKLYLWRQKGKBE"
Encoded_As = "EICTDGYIYZKTHNSIRFXYCPFUEOCKRN"
List = []
for i in range(len(Cipher_Text)):
As = "A" * len(Cipher_Text)
List.append(ord(Encoded_As[i]) - ord(As[i]))
Decrypted_Text = ""
for j in range(len(Cipher_Text)):
Decrypted_Text += chr(ord(Cipher_Text[j]) - List[j])
print(Decrypted_Text)
vim script.py
:wq
cat script.py
python3 script.py

As shown some letters are not capital letters just like the original cipher text, so we need to make sure that if a characters goes under the capital letter 'A' to add 26 to wrap around the alphabet:
Cipher_Text = "PNUKLYLWRQKGKBE"
Encoded_As = "EICTDGYIYZKTHNSIRFXYCPFUEOCKRN"
List = []
for i in range(len(Cipher_Text)):
As = "A" * len(Cipher_Text)
List.append(ord(Encoded_As[i]) - ord(As[i]))
Decrypted_Text = ""
for j in range(len(Cipher_Text)):
Subtract = ord(Cipher_Text[j]) - List[j]
if Subtract < ord('A'):
Subtract += 26
Decrypted_Text += chr(Subtract)
print(Decrypted_Text)
vim script.py
:wq
cat script.py
python3 script.py

Here is the correct password.

Last updated