[UTCTF2020]hill

# wznqca{d4uqop0fk_q1nwofDbzg_eu}
import re
import string
origin_str='wznqca{d4uqop0fk_q1nwofDbzg_eu}'
res=re.findall('[a-z]',origin_str,re.I)
print(''.join(res),len(res))
# wznqcad4uqop0fkq1nwofDbzgeu ,len=27
# utflag
from z3 import *
x1,y1,x2,y2=Ints('x1 y1 x2 y2')

cipher=[]
plain=[]
for _1,_2 in zip('wznqca','utflag') :
    cipher.append(string.ascii_letters.index(_1) )
    plain.append(string.ascii_letters.index(_2))
print(cipher,plain)
ret=solve(-1<x1,x1<27,-1<x2,x2<27,-1<y1,y1<27,-1<y2,y2<27,(x1*cipher[0]+y1*cipher[1])%26==20,
      (x2*cipher[0]+y2*cipher[1])%26==19,
      (x1*cipher[2]+y1*cipher[3])%26==5,
      (x2*cipher[2]+y2*cipher[3])%26==11)
y1 = 6
y2 = 21
x1 = 13
x2 = 3
# x1,y1= 13,6
# x2,y2= 3,21

pos=[]
decrypt=[]
# res='wznqcaduqopfkqnwofDbzgeu'
def str_index(chr1):
    return string.ascii_letters.index(chr1)
for each in range(0,len(res),2):
    if res[each].isupper(): #can only deal with one upper
        pos.append(each)
    if  res[each+1].isupper():
        pos.append(each+1)
    decrypt.append(string.ascii_letters[(str_index(res[each])*x1+str_index(res[each+1])*y1)%26])
    decrypt.append(string.ascii_letters[(str_index(res[each])*x2+str_index(res[each+1])*y2)%26])
print(decrypt)

for each in pos:
    decrypt[each]=decrypt[each].upper()
# flag{d4nger0us_c1pherText_qq}

res=re.sub('[a-zA-Z]',lambda M:decrypt.pop(0),origin_str)
print(res)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值