A delicious sup
Category
Baby warm-up Crypto
Description:Once you've decided on what ingredients to use, making a delicious soup is very simple!
以上を行うPythonプログラムを書きます。
#!/usr/bin/env python#-*- coding:utf-8 -*-import random#from flag import flagflag = '11d.3ilVk_d3CpIO_4nlS.ncnz3e_0S}M_kn5scpm345n3nSe_u_S{iy__4EYLP_aAAall'def encrypt(msg, perm):W = len(perm)while len(msg) % (2*W):msg += "."msg = msg[1:] + msg[:1]msg = msg[0::2] + msg[1::2]msg = msg[1:] + msg[:1]res = ""for j in xrange(0, len(msg), W):for k in xrange(W):res += msg[j:j+W][perm[k]]msg = resreturn msgdef encord(msg, perm, l):for _ in xrange(l):msg = encrypt(msg, perm)if 'ASIS{' in msg:print(msg + '\t' + str(_))if msg.startswith(flag):breakreturn msgW, l = 7, random.randint(0, 1337)l = 10000000perm = range(W)while True:random.shuffle(perm)print(perm)enc = encord(flag, perm, l)
実行すると次のようになります。perm = [1, 0, 5, 4, 2, 6, 3]のときに元の平文に戻ります。
(略)[1, 0, 5, 4, 2, 6, 3]ASIS{1n54n3ly_Simpl3_And_d3lic1Ous_5n4ckS_eVEn_l4zY_Pe0pL3_Can_Mak3}.. 1218
フラグは、
ASIS{1n54n3ly_Simpl3_And_d3lic1Ous_5n4ckS_eVEn_l4zY_Pe0pL3_Can_Mak3}