栅栏密码解密优化
本帖最后由 Culaccino 于 2019-11-14 14:38 编辑在做bugku逆向RE_Cirno的时候碰到一个栅栏发现解密的栅栏数和字符数对不上,于是自己优化了一下
writeup链接:https://blog.csdn.net/zhang644720213/article/details/100068670
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 + '*'
# 还原flag
lines += 1
arr = for i in range(0,len(result),lines)]
flag = ''
for i in range(len(arr)):
for j in arr:
flag += j
return flag[:length]
def encode(flag,num):
length = len(flag)
lines = ceil(length / num)
arr = for i in range(0,lines * num,num)]
flag = ''
for i in range(len(arr)):
for j in arr:
try:
flag += j
except:
pass
return flag
if __name__ == "__main__":
decode("fotl1eas0gvw{30Cr}1yrcnu",9)
好使,谢了
页:
[1]