Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
We found a brand new type of encryption, can you break the secret code? (Wrap with picoCTF{}) apbopjbobpnjpjnmnnnmnlnbamnpnononpnaaaamnlnkapndnkncamnpapncnbannaapncndnlnpna new_caesar.py
So we are given a script new_caesar.py
, let's analyse it.
So first off we know that the ALPHABET
is the first 16 letters in the lowercase alphabet. The key
is one character long, and is also in ALPHABET
. The flag has b16_encode()
run on it, and every letter in the result of that is run under shift()
. To reverse, it, we have to first undo shift()
and then b16_encode()
.
shift()
is a very simple function, although the arithmetic looks a bit strange. t1
is actually the index of c
in ALPHABET
, as it grabs the character code and then subtracts off that of a
. t2
is the same, but for the key. t2
is then added as a shift to t1
and the index in ALPHABET
is returned, so it's essentially a Caesar with a shift dictated by k
. We can undo this easily, by subtracting instead of adding:
As for b16encode()
, it calculates the 8-bit binary representation of the character code and then splits it into two 4-bit values, which are used as indices in ALPHABET
. We can undo this too.
The .zfill(4)
ensures that each representation of the two values is 4 bits long, which is very important for parsing it as an 8-bit bniary value at the end!
We then just have to brute force for every possible key
in ALPHABET
, getting 16
possibilities:
The only one that looks right is et_tu?_23217b54456fb10e908b5e87c6e89156
(given the title), and we submit that as the flag.
Full script:
A one-time pad is unbreakable, but can you manage to recover the flag? (Wrap with picoCTF{}) nc mercury.picoctf.net 11188 otp.py
We are given a script otp.py
and a remote service that serves the script. Let's analyse what it does.
It seems to first start up the process, then it loops an encrypt()
function:
startup()
has a short process:
So, it will read the flag from the file flag
and the key from the file key
. It will then grab the first len(flag)
bytes of key
.
Note this line:
is actually just an XOR operation that returns the result as a hex string. As such, it seems to use the bytes of key
as a one-time-pad, XORing it with the flag
and returning us the result.
Now let's move on to encrypt()
:
encrypt()
does the same kind of thing, except with our input! The only difference is here:
The end point will be looped around to the start point, so once the first KEY_LEN
bytes of the key file are used it will loop back around and start from the beginning. This makes it possible for us to gain the same OTP twice!
I'm going to use pwntools
for this process. First we grab the encrypted flag:
Now I will feed a string of length KEY_LEN - enc_flag_len
into the encrypt()
function. Why? This will make the stop
exactly 50000
, meaning the next encryption will have a start
of 0
again, generating the same OTP as it did for the original flag! Now because XOR is a involution - it undoes itself - we can send back the encrypted flag and it will undo the original XOR, returning us the flag!
Be careful that you decode the hex encoding and send the raw bytes!
The full script is as follows:
The one time pad can be cryptographically secure, but not when you know the key. Can you solve this? We've given you the encrypted flag, key, and a table to help UFJKXQZQUNB with the key of SOLVECRYPT
The table is simple - the you grab the plaintext character and the corresponding character from the key and cross-reference them to find the ciphertext character. To reverse it, you find the key character and go along the row (or column) until you find the ciphertext character, then you go perpendicular to it to find the corresponding plaintext character. This nets you CRYPTOISFUN
, so the flag is picoCTF{CRYPTOISFUN}
.
This is actually a Vigenère cipher, so you could also use an online tool to do it for you!
The numbers... what do they mean?
We get a bit of an image:
The {}
suggest that this is some sort of transposition, where letters are replaced with numbers while other characters are left the same. Since all the numbers are in the range 0-25
, it makes logical sense that each number is really the position of the letter in the alphabet. We can make a simple decryption script based off this assumption:
We get QJDPDUG{UIFOVNCFSTNBTPO}
. As we assume it starts with PICOCTF
, we can see that we are actually one index off - which makes sense, as strings are zero-indexed in Python, so we just need to use n-1
and we get the flag:
What happens if you have a small exponent? There is a twist though, we padded the plaintext so that (M ** e) is just barely larger than N. Let's decrypt this: ciphertext
Now we're getting onto proper cryptography. Here we are told that we are using RSA with a small exponent, but is just more than . This means we can't quite do a cube-root attack, but because it is just more than we can actually keep on adding multiples of onto and taking the cube root until we get the flag. As it is close, it's not infeasible to brute force. I use gmpy2's iroot
function to take the cube root.
Oracles can be your best friend, they will decrypt anything, except the flag's ciphertext. How will you break it? Connect with nc mercury.picoctf.net 10333
Upon connecting, we get the values of and as well as the encrypted ciphertext that represents the flag. We then have a decryption oracle, which can decrypt anything except for the flag.
Note that the ciphertext is decrypted as follows:
If we ask to decrypt instead, we get
Note the last congruence is because is odd, so .
This means that if we pass in the negative of , we can get the negative of the decryption!
Cryptography can be easy, do you know what ROT13 is? cvpbPGS{abg_gbb_onq_bs_n_ceboyrz}
The same as - check that writeup!
I have these 2 images, can you make a flag out of them? scrambled1.png scrambled2.png
As the images are the same dimensions, it makes sense to consider what could be done with the RBG values. Immediately, XOR springs to mind, and we make a quick script to XOR the pixel data:
This came up with an interesting output.png
, which definitely had the flag in it, but was quite hard to read:
After some trial and error and printing of the values, you notice that pretty much everywhere is pure white. To up the contrast a little, we make all the white into black:
And this was enough to spy the flag:
What if d is too small? Connect with nc mercury.picoctf.net 37455.
We are told is too small, so this is a classic Wiener's Attack. I discuss the technique , so I won't go over it again. Connecting to the server gives us , and . I will use SageMath for the continued fractions.
Decrypt this message.
A classic caesar cipher, we can decrypt it using an or python:
Cryptography can be easy, do you know what ROT13 is? cvpbPGS{arkg_gvzr_V'yy_gel_2_ebhaqf_bs_ebg13_uJdSftmh}
We are told that the flag is encrypted with ROT13, which is a simple substitution cipher that replaces every character with the character that is 13 spaces along the alphabet. For example, the character C
would be replaced by a P
:
You can see that C
is the 3rd index, and P
is in fact the 16th. But what if we want to encrypt the letter Y
, at index 25? Well, what we do here is we loop back to the beginning; if we do this, the character 13 positions after it is in fact L
!
Mathematically, we can see that the index that would be position 26
is actually looping back to position 0
, so we add on the 13
and take the remainder modulo 26. We can do this easily in Python, ignoring non-letter characters:
In RSA, a small e value can be problematic, but what about N? Can you decrypt this? values
This is typical RSA decryption. We are given n
, e
and c
.
If you don't know much about RSA, check out !
All we need are the factors of N
. Because it's small, we can try and check if the factors are known using . And they are! So from here it's just standard RSA:
There are other ways to do it too - you could calculate and multiply by that, which would yield you after decryption, and you'd just need to halve it, .
A type of transposition cipher is the rail fence cipher, which is described here. Here is one such cipher encrypted using the rail fence with 4 rails. Can you decrypt it?
So, you can use an online tool like here, or you can actually follow the wikipedia page it gives you, or you can play around until it works:
So the flag is picoCTF{WH3R3_D035_7H3_F3NC3_8361N_4ND_3ND_4A76B997}
Take each number mod 37 and map it to the following character set: 0-25 is the alphabet (uppercase), 26-35 are the decimal digits, and 36 is an underscore. Wrap your decrypted message in picoCTF.
Just follow the instructions, really.
A message has come in but it seems to be all scrambled. Luckily it seems to have the key at the beginning. Can you crack this substitution cipher?
So, we are told that the key is at the beginning! Let's see what we have:
So, the first line appears to be the "key". Well, if we write the alphabet under it:
There is a perfect correspondence! So, any instance of the character in the top list is meant to be substituted using the bottom list. We can easily make a python program to do it for us:
We get a text from The Gold-Bug, by Edgar Allen Poe and the flag too:
Pretty explicitly morse code, we go to an online decoder and have it spit out the flag:
Alternatively we could use something like Audacity to view the waveforms themselves, but nah.
Again, simply do what it tells you. For information on the inverse modulo a prime, check out my notes here!
Can you decrypt this message?
So the hint is that the message is encrypted with a Vigenere cipher using the key CYLAB
. Sure we could use an , but how about in python?
The way a vigenere cipher works is that the letters in the key are converted into integers based into their position in the alphabet, with 0
being a
and 25
being z
. Those values are then used as shift values for a per-letter caesar cipher - so in the case of CYLAB
, the first value is 3
and the second is 24
. Given the encrypted flag:
We then know that r
is the plaintext letter shifted over by 3
and g
is the plaintext letter shifted over by 24
(and looped around, in the same way a caesar cipher is). To this end, we can make a quick script:
We get the output
Which isn't quite the flag. Evidently, it's working.
After a lot of trial and error, it turns out that the problem is that we are looping throuhg them at the same pace, but in reality the key isn't even being incremented on the non-letter characters (for example the L
in the key
aligns with {
in the message
, nothing is done because it's not a character, but the loop still goes on to the next key character for the next decryption). In essence, we have to just stop the key from looping on those characters:
We found a leak of a blackmarket website's login credentials. Can you find the password of the user cultiris and successfully decrypt it? Download the leak here.
Opening up usernames.txt
and passwords.txt
in Pycharm, we see cultiris
is on line 378
of usernames.txt
so we go to line 378
of passwords.txt
and find an encrypted password:
The {}
are in place, implying that it's some sort of transposition cipher for the letters. We've done it numerous times, but we try a caesar cipher decode:
In fact the shift is 13, so it's just a ROT13.
It seems that another encrypted message has been intercepted. The encryptor seems to have learned their lesson though and now there isn't any punctuation! Can you still crack the cipher?
This time around, we don't even have spaces or full stops!
We can use a similar approach to last time, but this time we may have to use frequency analysis (as suggested by the last flag!) and even bi- and trigram analysis. This means finding common letters, or common groupings of 2/3 letters, and comparing it to what would typically occur in a regular english text.
However, first off, there is very clearly a flag at the end:
And we can use the same initial approach as last time and update the alphabet accordingly.
I can then see the following string:
so there is a word P*TITIO*
. According to a crossword solver, that's either petition
or petitios
. But ahead of it, there's even more:
This looks like COMPETITION
! Let's throw that in.
After spotting lots more words like cybersecurity
etc, I get the alphabet
:
And we use the decrypt again:
As we can see from the flag (and also the hint), ngram analysis was the way to go.
A second message has come in the mail, and it seems almost identical to the first one. Maybe the same thing will work again.
Similar to , this is a substitution cipher but without the key. We could use online tools, but let's think about how we could maybe determine it ourselves.
Firstly, I'm going to put the entire text to lowercase. I will set the alphabet to full underscores, and only fill it in once I know the transposition; the underscores will denote transpositions I do not know. In the transposition step, if the character is not know it prints it lowercase, while the ones I do know are printed uppercase.
Initially this prints the text out as is. However, let's see the flag at the end:
We can determine the characters for p
, i
, c
, o
, t
and f
because we know the flag format!
Now the plaintext when printed out looks more interesting, as it includes this:
Let's look at the rest of the text and see what we can determine.
The first word is CTFe
, implying that is should say CTFS
, as not much else can follow CTF
.
Then, later, it says
which looks like it should say CTFS ARE A ...
, and we can put those letters in too. By this point we have
And leter on the word PRACTICE
is already decrypted. Now you continue the process, seeing words such as SERwICE
. We eventually get
With the key
Note some letters are missing. The script currently looks like this:
Now we're gonna reuse the one from to transpose it for us (with a couple of minor modifications):
How about some hide and seek heh? Look at this image here.
Not the most enjoyable challenge. Gives us an image called atbash.jpg
, but no ciphertext yet. We actually have to use steganography techniques to extract the ciphertext from being embedded in the image, using steghide
:
The passphrase is empty. The encrypted.txt
file that is created has the following:
Based off the filename, we can assume it's an atbash cipher, which is essentially a transposition cipher where alphabet is flipped (so A
goes to Z
, B
goes to Y
, etc).
Our data got corrupted on the way here. Luckily, nothing got replaced, but every block of 3 got scrambled around!
So we are given the data
And also told that every block of 3 is scrambled the same way. Looking at the first block of 3, is should clearly say The
, so the order of reading it should be 3rd letter -> 1st letter -> 2nd letter. We make a quick python script to split it into triplets and rearrange: