In this challenge there is a encrypted file called flag.txt which contains the scrambled flag.
The encryption process works as follows
The encryption process works as follows
def encord(msg, perm, l): for _ in xrange(l): msg = encrypt(msg, perm) return msg W, l = 7, random.randint(0, 1337) perm = range(W) random.shuffle(perm)
l contains a random number - the number of times the function will be applied to the message and a shuffled perm array.
To solve this challenge first we need to construct a decrypt function
and then bruteforce the two random variables.
For bruteforce the fastest strategy I could come up with was to first iterate over perm and then for that perm apply the decrypt function 1337 times.
import random import itertools def decrypt(enc,perm): W = len(perm) msg = "-"*len(enc) for j in xrange(0,len(enc),W): for k in xrange(W): try: m = enc[k+j] except: #unknown bug pass msg = msg[:j+perm[k]] + m + msg[j+perm[k]+1:] msg = msg[::-1][0] + msg[:len(msg)-1] m = "" w = len(msg)/2 for i in range(len(msg)/2): m += msg[i]+msg[w+i] msg = m msg = msg[::-1][0] + msg[:len(msg)-1] return msg.strip(".") f = open("flag.enc","r") enc_c = f.read() print("Decrypting",enc_c) W = 7 l = 1337 for perm in itertools.permutations(range(W)): enc = str(enc_c) for _ in xrange(l): enc = decrypt(enc,perm) if enc.startswith("ASIS"): print(enc)
Bruteforce time ~ 2 mins
Is 1xbet korean sports legal? Sportsbook in Korea - Legalbet
ReplyDeleteIs 1xbet korean sports legal? Is 1xbet korean sports legal? Is 1xbet korean sports legal? Is 1xbet korean sports legal? Is 1xbet korean sports 1xbet in legal?