下面附上函数代码,求解出flag值 key值已经给出,求帮助啊,逆推过程应该怎么写啊
import base64
def encode(flag):
l1 = []
for a in flag:
l1.append(chr(int(ord(a)) - 10))
l1.reverse()#反向存储
mid = ''.join(list(l1))
key = base64.b64encode(mid)
print key
key = 'YmVVJ2ReT2ZqZVVpWSY=='
上边的代码缩进有点问题 代码在这里http://paste.ubuntu.com/23493247/
import base64
def encode(flag):
tmp_list = []
for a in flag:
tmp_list.append(chr(int(ord(a)) - 10))
tmp_list.reverse()
mid = ''.join(list(tmp_list))
key = base64.b64encode(mid)
return key
def decode(value):
tmp_str = base64.b64decode(value)
lists = list(tmp_str)
lists.reverse()
new_list = []
for x in lists:
tmp_x = chr(ord(x) + 10)
new_list.append(tmp_x)
new_list.reverse()
new_list.reverse()
print new_list
if name == '__main__':
strs = "123"
value = encode(strs)
ori_str = decode(value)
楼猪的代码里面对list进行反向的存储是每个循环都要做的吗,还是把所有的循环都走一遍了才进行的一次反向的存储,请注明。
l=[]
f=base64.b64decode(key)
for a in f:
l.append(chr(int(ord(a)) + 10))
l.reverse()
flag=''.join(list(l1))
上面的代码有点乱:
大早上起来看到你的回复给你写了个解码函数,其实么什么逻辑,就是根据你的加密函数的逻辑反着来一遍就行了:
def decode(value):
tmp_str = base64.b64decode(value)
lists = list(tmp_str)
lists.reverse()
new_list = []
for x in lists:
tmp_x = chr(ord(x) + 10)
new_list.append(tmp_x)
new_list.reverse()
new_list.reverse()
print new_list
这个函数传入你的加密函数的输出字符串,就可以输出原始的字符串