Binary Secrets - SMP CTF 2024 - Selection Round
Hi Everyone, this is Parvez Mosharaf Siam, a member of Knight Squad. Today, I will explain the solution to the Binary Secrets Challenge.
We are provided with two files:
Encrypted text: Contains the binary-encrypted message. Encryption code: Describes the process of how the text was encrypted.
SO here is our encrypted text:
10110000011000 10100011101000 10101010000000 100000101011000 10010100110000
1101000001000 11001110001000 11011010111000 11001001111000 10010100110000
10100111111000 10101110010000 11001001111000 1001010011000 10100001100000
1100110000000 11111010110000 11010110101000 100001001101000
Here is encrypted Code:
def x(y, z, w):
q = []
for t in y:
u = ord(t)
p = u * (z + w)
q.append(bin(p)[2:])
return q
def n():
z = 69
w = 67
y = "SMP{thisislooklikeflagisn'tit?}"
q = x(y, z, w)
d = ' '.join(q)
print(d)
if __name__ == "__main__":
n()
SO now check encrypted code how it is encrypted the text:
Here: y
The original message (in the example, y = "SMP{thisislooklikeflagisn'tit?}"). z
and w
Two integers, here z=69 and w=67. sum of this two value.
u = ord(t)
takes a single character t from the string y and returns its ASCII integer value.
For instance, ord('S') = 83, ord('{') = 123,
something like this
p = u * (z + w)
means each ASCII value is multiplied by 136.
Example: If t = 'S' (u=83), then p = 83 * 136 = 11288
bin(p)[2:]
creates a binary string representation of p. For p = 11288
, bin(11288)
is '0b10110000011000'
. Stripping '0b'
yields "10110000011000"
. Each character’s binary gets appended to list q.
Finally, the code joins them with spaces: ' '.join(q) and prints out the result.
Here is the summary of this encrypted code:
the “encrypted” message is just each character’s ASCII code multiplied by 136, then converted to binary.
SO we just need to convert the Binary to integar value and then just devide that value with 136 which is total sum of z and w
Once you have the ASCII code (e.g., 83), convert it back to a character with chr(83)
, which is 'S'
.
And here is final decryption code:
encrypted = "10110000011000 10100011101000 10101010000000 100000101011000 10010100110000 1101000001000 11001110001000 11011010111000 11001001111000 10010100110000 10100111111000 10101110010000 11001001111000 1001010011000 10100001100000 1100110000000 11111010110000 11010110101000 100001001101000"
chunks = encrypted.split()
z = 69
w = 67
sum_zw = z + w
decrypted_chars = []
for binary_str in chunks:
num = int(binary_str, 2)
ascii_code = num // sum_zw
decrypted_chars.append(chr(ascii_code))
original_message = ''.join(decrypted_chars)
print(original_message)
And then you will get your flag: