#!/bin/env python3
import sys
hextext = "66737a65"
finaltext = ""
cleartext = ""
for i in range(0, len(hextext) - 1, 2):
    c = '{}{}'.format(hextext[i], hextext[i+1])
    cleartext += chr(int(c, 16) ^ 0x12)
cur_size=0
bits_processed=0
for i in range(0, len(cleartext) - 1, 4):
    if (len(cleartext) - 4 * bits_processed) > 4:
        cur_size = 4
    else:
        cur_size = len(cleartext) - 4 * bits_processed
    for j in range(i+cur_size,i,-1):
        finaltext += cleartext[j-1]
    bits_processed+=1
print('Level 3 text: {}'.format(finaltext))
