Tags: reverse 

Rating: 5.0

![image](https://user-images.githubusercontent.com/68913871/134917337-78dfe6bb-78d0-4514-a8cb-563e84945340.png)
[digital_play.zip](https://github.com/Rookie441/CTF/files/7236565/digital_play.zip)

> Open the .dig file using [Digital](https://github.com/hneemann/Digital/releases/latest/download/Digital.zip). Clone the repo and run command `java -jar Digital.jar`

> Here, we can see the key to be `0x4d415253` as well as a circuit diagram of 9 XOR gates and 5 NOT gates

![image](https://user-images.githubusercontent.com/68913871/134917360-a172ec26-1bea-4495-a980-1a1d8429fdff.png)

> The enc.txt file is in binary format, so we will need to convert them to hex and `XOR` it with the key. Before that, we need to `NOT` Ciph 1,3,5,7,9 which are the odd Ciphs.

```
00110110111111100000011000101 100001000000100000011000010101 001001111110101001110011001011 1111100000101010000110100010000 011011111011001110111011011001 1111100000101010110011100001100 010011111011001100100011110011 1100001101100001011101100110 0000010111100111100100011010001
```

> This is the code to `NOT` the odd Ciphs and convert to hex format:

```python
enc = ["00110110111111100000011000101","100001000000100000011000010101","001001111110101001110011001011","1111100000101010000110100010000","011011111011001110111011011001","1111100000101010110011100001100","010011111011001100100011110011","1100001101100001011101100110","0000010111100111100100011010001"]

def flip(text):
binstring = ""
for i in text:
if i == "1":
binstring+="0"
elif i == "0":
binstring+="1"
return binstring

#flip 1,3,5,7,9
enc_new = []
for i in range(len(enc)):
if i%2 == 0:
enc_new.append(flip(enc[i]))
else:
enc_new.append(enc[i])

#convert to hex strings
enc_hex = []
for binary in enc_new:
enc_hex.append((hex(int(binary, 2))))
print(enc_hex)
```

> The output is a list of hexadecimal strings.

```
['0x19203f3a', '0x21020615', '0x36056334', '0x7c150d10', '0x24131126', '0x7c15670c', '0x2c13370c', '0xc361766', '0x7d0c372e']
```

> Store them in a list of hexadecimal numbers and `XOR` with the key to get the flag.

```python
key = 0x4d415253
c = [0x19203f3a, 0x21020615, 0x36056334, 0x7c150d10, 0x24131126, 0x7c15670c, 0x2c13370c, 0xc361766, 0x7d0c372e]
print(b"".join(bytes.fromhex(hex(key ^ i)[2:]) for i in c).decode("utf-8"))
```

`TamilCTF{D1g1T_CiRCu1T5_aRe_AwE50Me}`

Original writeup (https://github.com/Rookie441/CTF/blob/main/Storage/Writeups/TamilCTF2021_Writeup.md#digital-play).