# interencdec

starting off the challenge we were given a file upon reading the file

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FH8gWlkifkLQF8Iw1VyyA%2Fimage.png?alt=media&#x26;token=cc9bd4d6-3133-45c6-96a9-903950c47138" alt=""><figcaption></figcaption></figure>

it looks like a base64 string already so i created my own python code to decode using base64

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FFcjdvhBWp0WVkYqTt41s%2Fimage.png?alt=media&#x26;token=f01dcaf5-d056-4a32-a95f-f643a38fc8de" alt=""><figcaption></figcaption></figure>

we successfully decoded the data but it looks like the author used a double encoding so we can try to decode it again

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F5EpHW8HzYJPVOFNkXulM%2Fimage.png?alt=media&#x26;token=a96922ac-c704-451e-9958-a3b85d7a9188" alt=""><figcaption></figcaption></figure>

now were getting close based by the pattern im suspecting that this chall is using rot13 to modify the flag so based from the numbers i checked by printing the ord(w) and ord(p) i noticed that the text was shifted by 7 so we can just reverse that by doing -7

```python
import base64

data = b""

with open('chall.txt', 'rb') as a:
    data += a.read()[:-1]

flag = base64.b64decode(data)[2:-2]
flag2 = base64.b64decode(flag).decode('utf-8')

solve = ""

for i in flag2:
    b = ord(i)
    if(b >= ord('a') and b <= ord('z')):
        b -= 7
        if(b < ord('a')):
            b += 26
    elif(b >= ord('A') and b <= ord('Z')):
        b -= 7
        if(b < ord('A')):
           b += 26
    solve += chr(b)

print(solve)
```

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FVVMeFic1xCFamlIa8zLo%2Fimage.png?alt=media&#x26;token=0b93061a-5c01-4f52-a929-73e4381cbadc" alt=""><figcaption></figcaption></figure>
