#!/usr/bin/env python
# encoding: utf-8
import base64
def encode(message):
s = ''
for i in message:
x = ord(i) ^ 32
x = x + 16
s += chr(x)
return base64.b64encode(s)
correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
flag = ''
print 'Input flag:'
flag = raw_input()
if encode(flag) == correct:
print 'correct'
else:
print 'wrong'
逻辑还是很好懂的,只需要逆推就可以了。先对输入进行32异或,然后加16,最后base64加密.
反向计算,先base64解密,然后-16,最后与32异或就可以获得原flag。上脚本:
#!/usr/bin/env python
#encoding :utf-8
import base64
text = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
flag=''
s=base64.b64decode(text)
for i in s:
i = chr((ord(i)-16)^32)
flag+=i
print flag