本帖最后由 Culaccino 于 2019-11-14 14:38 编辑
在做bugku逆向RE_Cirno的时候碰到一个栅栏发现解密的栅栏数和字符数对不上,于是自己优化了一下
writeup链接:https://blog.csdn.net/zhang644720213/article/details/100068670
[Python] 纯文本查看 复制代码 from math import ceil
def decode(flag,num):
length = len(flag) # flag的长度
lines = length // num # 判断共有几层并减一
remainder = num * (lines + 1) - length #相差的数量
# 补全flag
result = flag[:length-lines*remainder]
for i in range(remainder-1,-1,-1):
result += flag[length-(i+1)*lines:length-i*lines] + '*'
# 还原flag
lines += 1
arr = [result[i:i+lines] for i in range(0,len(result),lines)]
flag = ''
for i in range(len(arr[0])):
for j in arr:
flag += j[i]
return flag[:length]
def encode(flag,num):
length = len(flag)
lines = ceil(length / num)
arr = [flag[i:i+num] for i in range(0,lines * num,num)]
flag = ''
for i in range(len(arr[0])):
for j in arr:
try:
flag += j[i]
except:
pass
return flag
if __name__ == "__main__":
decode("fotl1eas0gvw{30Cr}1yrcnu",9)
|