Tags: python rev crypto 

Rating:

This challenge consists of 2 parts, solving the first part will give you the key for decrypting the second part. Both parts are reversable.

Part 1:

```
def bases_to_str(msg, count):
count=(count%4)+1
if count == 1:
return b64decode(msg.decode())
elif count == 2:
return b32decode(msg.decode())
elif count == 3 :
return b85decode(msg.decode())
else:
return unhexlify(msg.decode())

def rev_msg(msg_enc):
count=0
msg_dec = ''
msg_spl = msg_enc.split('|')[:-1]
for frag in msg_spl:
msg_dec += bases_to_str(long_to_bytes(frag), count).decode()
count+=1
return msg_dec

msg_enc = '5943134639005711677|5491378081737038141|366970695973|3833466206172886320|5640277313745009981|5351739078059639101|302416945480|3762814891798442803|6354696933901548861|5139258452082510141|305635213400|3688506584576963897|5568232986773634365|5139251786226882877|357308525154|3847819437120304993|7008813202989464893|5786655223480211773|306693940071|3689633605503693413|'
msg_dec = rev_msg(msg_enc)
print(msg_dec)
```

Output from server:

```
nc crypto.zh3r0.ml 3871
Hello!
Welcome to Xor analysis..
There are two parts.
All the best ;)

Here is the first part:

5943134639005711677|5491378081737038141|366970695973|3833466206172886320|5640277313745009981|5351739078059639101|302416945480|3762814891798442803|6354696933901548861|5139258452082510141|305635213400|3688506584576963897|5568232986773634365|5139251786226882877|357308525154|3847819437120304993|7008813202989464893|5786655223480211773|306693940071|3689633605503693413|
Enter the decoded message:G00D_TH3_FIRST_P4RT_I5_D0N3_HER3_I5_4_F14G_F0R_Y0U_H4RD_W0RK_=_zh3r0{f4k3_f14g}.
You have done well.
Here is the key: 140262390255733908276964893730429404145946321017929888946337794323005965712203877415028
```

Part 2:

```
key = long_to_bytes(140262390255733908276964893730429404145946321017929888946337794323005965712203877415028).decode()
key_list=[hexlify(final_key[i:i+4].encode()).decode() for i in range(0,len(key),4)]
table={} # Data omitted for readability

def rev_flag(xor_list):
final_list=[strxor(i,j.encode()) for i,j in zip(xor_list,key_list)]
list_final=[frag.decode() for frag in final_list]
list_flag = rev_final_list(list_final, 2) # rand_num is a random number from 2 to 4. for this msg 2 worked.
flag = unhexlify(''.join(list_flag)).decode()
print(flag)

def rev_final_list(list_final, rand_num):
list_flag = []
for c in list_final:
chr=c
num=0
while num < rand_num:
chr=rev_table(chr[:2])+rev_table(chr[2:4])+rev_table(chr[4:6])+rev_table(chr[6:])
num+=1
list_flag.append(chr)
return list_flag

def rev_table(chr):
for x in table:
for y in table[x]:
if table[x][y] == chr:
return x + y

xor_list = [b'\x01\x0f\x05V\x04\x06\x06Z', b'U\x02S\x02\x04RP\n', b'\x06V\x0fSRW\x05_', b'\x06S\x0eXVV\x0bT', b'\x07\x03\x07\x03\x03\x0c\x03Q', b'\x0bUS\x07U\x01ST', b'\x07X\x0bTT\x02RV', b'WV\x03V\x07V\x02U', b'\x04\x00\x03\n\x02\x0c\x06\x02']
rev_flag(xor_list)
```

Output:

```
You completed the first part
Here is the second and final part ;)
GOOD LUCK DECODING!!!

[b'\x01\x0f\x05V\x04\x06\x06Z', b'U\x02S\x02\x04RP\n', b'\x06V\x0fSRW\x05_', b'\x06S\x0eXVV\x0bT', b'\x07\x03\x07\x03\x03\x0c\x03Q', b'\x0bUS\x07U\x01ST', b'\x07X\x0bTT\x02RV', b'WV\x03V\x07V\x02U', b'\x04\x00\x03\n\x02\x0c\x06\x02']
Enter the flag:zh3r0{Y0u_4r3_4_v3ry_G00d_4nalys3r!}
Perfect you got the flag ;)
Go submit it!!!
```