哪位能把下面这段javascript 转成Python
functionB(a){varb="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="...
function B(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var c,d,e,f,g,h,i,j,k=0,l=0,m="",n=[];if(!a){return a}a+="";do{f=b.indexOf(a.charAt(k++));g=b.indexOf(a.charAt(k++));h=b.indexOf(a.charAt(k++));i=b.indexOf(a.charAt(k++));j=f<<18|g<<12|h<<6|i;c=j>>16&255;d=j>>8&255;e=j&255;if(h==64){n[l++]=String.fromCharCode(c)}else if(i==64){n[l++]=String.fromCharCode(c,d)}else{n[l++]=String.fromCharCode(c,d,e)}}while(k<a.length);m=n.join("");return m}
展开
展开全部
应该是这样的:
def B(a):
b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
k=0
m=""
n=[];
if not a:
return a
a+=""
while True:
f=b.find(a[k])
k += 1
g=b.find(a[k])
k += 1
h=b.find(a[k])
k += 1
i=b.find(a[k])
k += 1
j=f<<18|g<<12|h<<6|i
c=j>>16&255;
d=j>>8&255;
e=j&255;
if h==64:
n.append(chr(c))
elif i==64:
n.append(chr(c)+chr(d))
else:
n.append(chr(c)+chr(d)+chr(e))
if k>=len(a):
break
m = "".join(n)
return m
print B('ABCDEFGH')
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |