Tags: xor 

Rating:

### Question

For none and none, there is always none

For none and one, there can be only one

For one and one, there is nothing but none

codeFile.txt

Sometimes, I sing to myself

Love is a burning thing

And it makes a firery ring

Bound by wild desire

I fell in to a ring of fire

### Approach
Let's have a look at the first poem. That's not just a poem. Is it?
```
None None None
None One One
One None One
One One None
```
XOR ??

On opening codefie.txt we get a really long ascii text consisting of nothing but 0s and 1s and no `\n` terminators.
```
00000110000000000001111000001011000000000011101101011101000000000010001001000001000100010001110101010010010001100000101100000001000101010100111001010100001000100100011101001110001101010010010001100001001011010000010101010011000000010100111100000000001010110000010000001001000101110000011001000001000100110101100101000110010110110100010001001001010100100100100000011001010000010101101101001110100001011000101011010001010011110010011000001011000101000101010000000111000101000100001000010010000110110100110001010101000100100100100001000101010000010101100101000010010101100010001101101001010101110000011100010110010011000000110101001110010010010010111101001101000100010001110101001001000000100100000100011100010010010001110100001110010011100000100000000011010100100100101001001001000000010000101001100100001011100101011100010100000011000001100000001001010100100100010101001110000110010001101001010011000010000100001100001011000101000001110001000010010010010000111100001001010001000101001000001000000011010001001101001111000111010100100000000000001010110001110000010001000011010010101000100110010001100101011100100110000011110000011101001000010000110001110001010111000000110101100101010011000011010000110001010111000011010100001101001110000100000000111000011110000000000110111100100101010011100001000001001000000100010000010100000000010100110100011000000011000001110100110100010110000111000101001000000101000010100001100101011000000000000000010100000110000101010000100100001001010100100111111000110011000001110000011001010101000001010001010101010100000010110001101000011100010000100101001101001101010011100000011001010101000000000000101100010111010010010100110100010010000000010001101100000001000111010010011001110100000011010001011001010000000101110000101000000111000001100100110000000011000111110000000000001111000001110101001000010001011000100011000101001000000010010100000100000110000011000001110001000111010100110001101100000111010001110000001100011010010100100000101001101100011010010100100000001111000101100100110000001111010000010001101100001011000100010001110100001110010000010100011100001011000100100001011100000011000100100001011001010111010100100010110100000000000111010011100001000011010111110000101101001101000100110011110101000110001100010011101100111111010001010000101001001011010011100011110001000101010001000001100000010110000111010000110001001011000010100000000000000000000000000000110001000110000010110001110101010111000001100110001100110010010011100000000001000101000100010001100001001001000000000000010100001101000011010000000001000101000100010100000100000100000101100100001100010110010000010001101000000000000100110000011100001011000101110010101000110111000000010000110101000011000011000101100000000000000101100001110100010111010011100001011101000101010100110001011000011100000111000000110100000111010001010101011000000111010101010000000100000001000001100110010000110000010010000000101001000110010100100000000100000111000101000000000000111011000000110100111000001000000011000000000100010110011011110011000101001000001100010100100000000000000011000000101101000111010000100000111000000101010010110000111100000111000101010100010101101000001101010000011000000001000000000001011100001001000100100000011000000100010000110001101100000011010100100000010100010101000100110000000100000000000010110000101000000000000001110000010100000100000011000001101000100111001110110000000100001110000010110000000000001011000011010001010000010101000100110001101001001110000010110100100100001100000100000100100100011011000101000000000001010011010100100000010100011100000100010001110001100111001110100000110001000110000001000100110000011110010001010000010000001010000111100100110000010000000000000000000001010011000000100000110000011000000101100000000000000010010011110001011000011000000001010000100100000000001010100011100000000001010110000100100001000010000101000001101000000000000111010000011000000110010100100000001100001000000000010000110001001110000100000000100100010111010101000101001100011000000001000000111000000001011110000110100101000001000010000000000101001100000001000101010100000100000011000100110000010001010011110100010000000100010011010000011100010100000111000000000100011011010000100100011101000110000000000000110000001011010001110101000000011101000011110101001100001001000001110101001000000110011001010010011101000011000100100001011100011010000001110000110001000100000011100001100100001010000011000100000101000100000110110000010100001111010010000100010100001001000011100000010100000101001010100010000000000010000010000000110100010110000001000000010001000011000011010100110000010010000110010000010000010100010001010101011100010010000011110000011001000100000110100000011000000101000011010100010100000101011000100010100000001101000011000000000000001100000101010101001000001100000100000001011001001110000110110100010101001101010000100000000100011010000010110101001101000010010010010000000100011110000111000000111100011110011011110111010001001010001100010100100000010111010010010010001100000110010011100100111100001111010011100100011000101011000111100000010001101001001111110100101001001011
```
I figured out somehow, we had to XOR the contents of this file using the poem as a key. So I divided the text at intervals of 8, converted the binary to ascii and tried XORing with the 1st few characters.

```
l1 = []
for i in range(0, len(shit), 8):
l1.append(int(shit[i:i + 8], 2))

text = """Love is a burning thing
And it makes a firery ring
Bound by wild desire
I fell in to a ring of fire"""

for i in range(30):
print(chr(l1[i] ^ ord(text[i])), end='')
```
`John R. Cash (born J. R. Cash;`

So far so good! I tried using the poem as the key to repeatedly XOR with the characters in list `l1` but this was the output.
```
John R. Cash (born J. R. Cash; February 26, 1932 – September 12, 2003) was an American singer, so(A!q,qzr$n{o!f*es<6!f.....
```
All ok till the 99th(which is the length of `text`) character, followed by gibberish. I figured out this must be a part of a biography copied from somewhere on the internet. So I googled the obtained text. And saw the exact same thing on wikipedia. So I figured out that in order to get a part of the key, I had to copy a few more lines from wikipedia and XOR it with the `l1` list.

```
text = """John R. Cash (born J. R. Cash; February 26, 1932 – September 12, 2003) was an American singer, songwriter, musician, and actor. Much of Cash's music contained themes of sorrow, moral tribulation, and redemption, especially in the later stages of his career."""
for i in range(len(text)):
print(chr(l1[i] ^ ord(text[i % len(text)])), end='')
```
```
Love is a burning thing
And it makes a firery ring
Bound by wild desire
I fell in to a ring of fire
I fell into a burning ring of fire
I went down, down, down
And the flames went higher
And it burns, burns, burns
The ring of fire
The ring of fire
I fell into
```
So it's quite easy to figure out that we have to XOR it with the WHOLE lyrics of the song. And that too the lyrics must be the exact same as the one used in the question in order to avoid avalanche effect.

```
text = """Love is a burning thing
And it makes a firery ring
Bound by wild desire
I fell in to a ring of fireI fell in to a burning ring of fire
I went down, down, down
And the flames went higherAnd it burns, burns, burns
The ring of fire
The ring of fire
I fell in to a burning ring of fire
I went down, down, down
And the flames went higher
And it burns, burns, burns
The ring of fire
The ring of fire"""
for i in range(len(text)):
print(chr(l1[i] ^ ord(text[i % len(text)])), end='')
```
Note : Some kid with a weird sense of humour replaced the fiery with firery, which was causing a lot of trouble initially.

```John R. Cash (born J. R. Cash; February 26, 1932 – September 12, 2003) was an American singer, so-?1q`t);+nmusician, and actor. Much of Cash's music contained themes of sorrow, moral ?]c&

Original writeup (https://github.com/x-0117/CTF-Writeups/blob/main/TAMU%20CTF/Ring%20of%20Fire.md).