# #808080 — CTF writeup

**Author:** seyya

***

## Description

```
#808080
author: seyya
gray code ? nah grey code
0010111100011010000101111111110110010010000100010111011001000110010000011111101101100111010000010101011001111110010000000111010001111110010000011
http://chall.ehax.in:8076/
Note: flag format for this challenge is CTF{...}
```

***

## The Website

```
http://chall.ehax.in:8076/
```

![](https://raw.githubusercontent.com/wal-z1/ctf-writeups/main/.gitbook/assets/grey-code-page.png)

The page presents a **circular wheel** with:

* 5 concentric circles (5 bits)
* 32 positions around the wheel
* Binary input (0 or 1) per circle per position
* Validation: all 32 entries must be

That validation is the definition of Gray code. `2^5 = 32` so this is basically a **5-bit Gray code** written on the circle

***

## 5-bit Gray Code

so first thign to try is to type the actual normal gray code

```
00000
00001
00011
00010
00110
00111
00101
00100
01100
01101
01111
01110
01010
01011
01001
01000
11000
11001
11011
11010
11110
11111
11101
11100
10100
10101
10111
10110
10010
10011
10001
10000
```

**you read each binary number from the inside out ... bit 0 (the innermost circle) is the rightmost digit ... and bit 4 (the outermost circle) is the leftmost digit**

So for position 0 `(00000)`: all circles = 0 and For position 2 `(00011)`: innermost two circles = 1, outer three = 0. And so on...

***

## Filling the Wheel

**Circle 1 (bit 4, outermost)**

```
12–27
```

**Circle 2 (bit 3)**

```
4–19
```

**Circle 3 (bit 2)**

```
0–7, 16–23
```

**Circle 4 (bit 1)**

```
0, 1, 6, 7, 8, 9, 14, 15, 16, 17, 22, 23, 24, 25, 30, 31
```

**Circle 5 (bit 0, innermost)**

```
1, 2, 5, 6, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 29, 30
```

The wheel accepted this input but the decoded output was wrong it gave random text at first

***

## Gibberish

```
GXJBKVI_DGSHI&KSIWAZIV_AL}VHC
```

The flag format is `CTF{...}`. Checking the first three characters:

```
G → C  (-4)
X → T  (-4)
J → F  (-4)
```

Everything is shifted by 4 .. yeah you might wanna try ROT but that didnt work so what about the gray code itself ? Gray code is **cyclic** and us rotating the sequence still produces a valid Gray code. So instead of starting at position 0 (`00000`), we shift the starting point by 4 "numbers"

New start of the sequence:

```
00110
00111
00101
00100
...
```

I re-entered the bits into the wheel and as we thought

***

## Second Decode — Flag

```
CTF{GREY&CODE#GOES_VERY_H@RD}
```

Flag ACCEPTED ![](https://raw.githubusercontent.com/wal-z1/ctf-writeups/main/.gitbook/assets/grey-code-flagaccept.png)
