---
description: X Gon' Give It To Ya
---

# Entry

> Entry task for crypto
>
> MD5 (entry.zip) = 7c1ad8ac9871e3fa788c4ac977108833
>
> **Author:** mechfrog88

{% hint style="info" %}
**Take Note:** For this challenge, you need to have a rough understanding of how [bitwise](https://en.wikipedia.org/wiki/Bitwise_operation) operation works.&#x20;
{% endhint %}

We were given a Python file, with the `FLAG` variable as `grey{...}`

Therefore, we figured that we have to get the flag with the Python file given!

```python
import secrets

FLAG = b'grey{...}'

assert len(FLAG) == 40

key = secrets.token_bytes(4)

def encrypt(m):
    return bytes([x ^ y for x, y in zip(m,key)])

c = b''
for i in range(0, len(FLAG), 4):
    c += encrypt(bytes(FLAG[i : i + 4]))

print(c.hex())

# 982e47b0840b47a59c334facab3376a19a1b50ac861f43bdbc2e5bb98b3375a68d3046e8de7d03b4
```

&#x20;There are a few things we took note of;

1. Key
2. Encrypt function
3. Flag
4. Hex output (commented out at the bottom of the code)

We were given the **hex output**, therefore we realized that we have to **reverse** the hex output in order to get the flag! :fire:&#x20;

The `key` variable tells us that the **secret key** is 4 bytes long.&#x20;

Given the `FLAG` variable, we know that "grey" is the the first 4 characters.&#x20;

The first 4 bytes of the **hex** output is `98 2e 47 b0`

**Encrypt** **function** showed `x ^ y` at the return statement, therefore, it is doing an [**XOR**](https://www.pcmag.com/encyclopedia/term/xor) operation.

Given the information above, we deduced that `x ^ y` equals to `grey ^ 982e47b0`&#x20;

Using a online XOR [calculator](https://xor.pw), we got `ff5c22c9`.&#x20;

We will take note of `ff5c22c9` as that is our secret key to solve this challenge!

![secret key!!](https://1326575018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWOW1TQuFBNIp3aDtWk3v%2Fuploads%2Fr9P3x4GOh29u3HBzuR9l%2FScreenshot%202022-06-12%20at%206.28.32%20PM.png?alt=media\&token=3403269b-0946-4b99-bb57-b20f34a937fd)

What we did next was simply just reverse the whole operation using the **Secret Key** that we managed to figure out and **Hex** output that was given to us!

```python
import secrets

FLAG = bytes.fromhex('982e47b0840b47a59c334facab3376a19a1b50ac861f43bdbc2e5bb98b3375a68d3046e8de7d03b4')

key = bytes.fromhex('ff5c22c9')

def encrypt(m):
    return bytes([x ^ y for x, y in zip(m,key)])

c = b''
for i in range(0, len(FLAG), 4):
    print(c)
    c += encrypt(bytes(FLAG[i : i + 4]))

print(c)
```

Flag: `grey{WelcomeToTheGreyCatCryptoWorld!!!!}`



Also did anyone noticed that XOR sounds like the song from Deadpool? No? Alright :disappointed:

![X Gon' Give It To Ya](https://1326575018-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWOW1TQuFBNIp3aDtWk3v%2Fuploads%2FoWps09DN7K71zKuiKCJd%2FScreen-Shot-2018-03-22-at-9.36.45-AM.png?alt=media\&token=f6c18099-4a2d-4106-ab25-00354597b8dd)
