直接放上代码:
import base64
class changeWorker:def thunderToNormal(self,url):if url.startswith('thunder://')or url.startswith('Thunder://'):mystr = url[10:]else:mystr = urlmystr = bytes(mystr, encoding = "utf8")missing_padding = 4 - len(url) % 4if missing_padding:mystr += b'=' * missing_paddingmystr2 = base64.decodebytes(mystr)#result = str(mystr2,'utf-8')result = mystr2.decode()return result[2:-2]mychangeWorker = changeWorker()
while 1:mystr = input('input thunder URL')print(mychangeWorker.thunderToNormal(mystr)
一个base64编码的简单运用。
PS:发现在转换后如果链接中存在中文的话会出现类似"%E9%9F%A9%E7%89%88%E4%B8%AD%E8%8B%B1%E5%8F%8C"的utf-8编码,不知道是否可以作进一步转换。