```#!/usr/bin/env python2from random import shuffleimport itertoolsimport sys
W = 7 perm = range(W)ps = list(itertools.permutations(perm))msg = open("output").read()                           #  L{NTP#AGLCSF.#OAR4A#STOL11__}PYCCTO1N#RS.Sdmsg = msg
if len(msg) % 14:    print "wrong length"    sys.exit(1)
def dex0r():    global W, perm, msg    for i in xrange(100):        # 1) reorder every 7 characters according to permutaion        res = ""        for j in xrange(0, len(msg), W):             for k in xrange(W):                 res += msg[j:j+W][perm[k]]         msg = res    
        # 2) move last character to beginning        msg = msg[-1:] + msg[:-1]
        # 3) combine even and odd chars back        evens = msg[0:int(len(msg)/2)]        odds = msg[int(len(msg)/2):len(msg)]        msg = ''.join(a+b for a,b in zip(evens, odds))
        # 4) move last letter to beginning        msg = msg[-1:] + msg[:-1]
a=0while a < len(ps):    perm = ps[a]    dex0r()    if "FLAG" in msg:        print msg     msg = dmsg    a += 1```