关于加密解密 Base64 and URL and Hex Encoding and Decoding

时间:2021-05-25

今天想换一下Discuz论坛的风格,谁知下载风格文件后,发现竟然是通过Base64加密过的
小林给推荐了个解密的页面,提取出代码如下:
复制代码 代码如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<title>Base64andURLandHexEncodingandDecoding</title>
<metaname="description"content="EncodesordecodesdatainBase64orURLencodingusingclientsideJavaScript"/>
<metaname="keywords"content="base64,base64,urlencode,urldecode,hexencode,hexencode,hexdecodehexdecode,javascriptbase64,javascriptbase64,javascripturlencode,javascripturldecode,javascripthexencode,javascripthexdecode"/>
<linkrel="shortcuticon"href="http://ostermiller.org/favicon.ico"type="image/x-icon"/>
<scriptlanguage=javascripttype="text/javascript">
<!--
functionurlDecode(str){
str=str.replace(newRegExp('\\+','g'),'');
returnunescape(str);
}
functionurlEncode(str){
str=escape(str);
str=str.replace(newRegExp('\\+','g'),'%2B');
returnstr.replace(newRegExp('%20','g'),'+');
}
varEND_OF_INPUT=-1;
varbase64Chars=newArray(
'A','B','C','D','E','F','G','H',
'I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X',
'Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v',
'w','x','y','z','0','1','2','3',
'4','5','6','7','8','9','+','/'
);
varreverseBase64Chars=newArray();
for(vari=0;i<base64Chars.length;i++){
reverseBase64Chars[base64Chars[i]]=i;
}
varbase64Str;
varbase64Count;
functionsetBase64Str(str){
base64Str=str;
base64Count=0;
}
functionreadBase64(){
if(!base64Str)returnEND_OF_INPUT;
if(base64Count>=base64Str.length)returnEND_OF_INPUT;
varc=base64Str.charCodeAt(base64Count)&0xff;
base64Count++;
returnc;
}
functionencodeBase64(str){
setBase64Str(str);
varresult='';
varinBuffer=newArray(3);
varlineCount=0;
vardone=false;
while(!done&&(inBuffer[0]=readBase64())!=END_OF_INPUT){
inBuffer[1]=readBase64();
inBuffer[2]=readBase64();
result+=(base64Chars[inBuffer[0]>>2]);
if(inBuffer[1]!=END_OF_INPUT){
result+=(base64Chars[((inBuffer[0]<<4)&0x30)|(inBuffer[1]>>4)]);
if(inBuffer[2]!=END_OF_INPUT){
result+=(base64Chars[((inBuffer[1]<<2)&0x3c)|(inBuffer[2]>>6)]);
result+=(base64Chars[inBuffer[2]&0x3F]);
}else{
result+=(base64Chars[((inBuffer[1]<<2)&0x3c)]);
result+=('=');
done=true;
}
}else{
result+=(base64Chars[((inBuffer[0]<<4)&0x30)]);
result+=('=');
result+=('=');
done=true;
}
lineCount+=4;
if(lineCount>=76){
result+=('\n');
lineCount=0;
}
}
returnresult;
}
functionreadReverseBase64(){
if(!base64Str)returnEND_OF_INPUT;
while(true){
if(base64Count>=base64Str.length)returnEND_OF_INPUT;
varnextCharacter=base64Str.charAt(base64Count);
base64Count++;
if(reverseBase64Chars[nextCharacter]){
returnreverseBase64Chars[nextCharacter];
}
if(nextCharacter=='A')return0;
}
returnEND_OF_INPUT;
}
functionntos(n){
n=n.toString(16);
if(n.length==1)n="0"+n;
n="%"+n;
returnunescape(n);
}
functiondecodeBase64(str){
setBase64Str(str);
varresult="";
varinBuffer=newArray(4);
vardone=false;
while(!done&&(inBuffer[0]=readReverseBase64())!=END_OF_INPUT
&&(inBuffer[1]=readReverseBase64())!=END_OF_INPUT){
inBuffer[2]=readReverseBase64();
inBuffer[3]=readReverseBase64();
result+=ntos((((inBuffer[0]<<2)&0xff)|inBuffer[1]>>4));
if(inBuffer[2]!=END_OF_INPUT){
result+=ntos((((inBuffer[1]<<4)&0xff)|inBuffer[2]>>2));
if(inBuffer[3]!=END_OF_INPUT){
result+=ntos((((inBuffer[2]<<6)&0xff)|inBuffer[3]));
}else{
done=true;
}
}else{
done=true;
}
}
returnresult;
}
vardigitArray=newArray('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
functiontoHex(n){
varresult=''
varstart=true;
for(vari=32;i>0;){
i-=4;
vardigit=(n>>i)&0xf;
if(!start||digit!=0){
start=false;
result+=digitArray[digit];
}
}
return(result==''?'0':result);
}
functionpad(str,len,pad){
varresult=str;
for(vari=str.length;i<len;i++){
result=pad+result;
}
returnresult;
}
functionencodeHex(str){
varresult="";
for(vari=0;i<str.length;i++){
result+=pad(toHex(str.charCodeAt(i)&0xff),2,'0');
}
returnresult;
}
functiondecodeHex(str){
str=str.replace(newRegExp("s/[^0-9a-zA-Z]//g"));
varresult="";
varnextchar="";
for(vari=0;i<str.length;i++){
nextchar+=str.charAt(i);
if(nextchar.length==2){
result+=ntos(eval('0x'+nextchar));
nextchar="";
}
}
returnresult;
}
//--></script>
</head>
<body>
<formname=codeonsubmit="returnfalse()">
<textareaname=textstyle='width:100%;height:75%;'onfocus='if(this.value=="Entertexttoencodeordecodehere."){this.value="";}'>Entertexttoencodeordecodehere.</textarea>
<table>
<tr><tdalign=center>
<inputvalue="Encode"type=buttononclick="document.code.text.value=urlEncode(document.code.text.value);">
</td><tdalign=center>
URL
</td><tdalign=center>
<inputvalue="Decode"type=buttononclick="document.code.text.value=urlDecode(document.code.text.value);">
</td></tr>
<tr><tdalign=center>
<inputvalue="Encode"type=buttononclick="document.code.text.value=encodeBase64(document.code.text.value);">
</td><tdalign=center>
Base64
</td><tdalign=center>
<inputvalue="Decode"type=buttononclick="document.code.text.value=decodeBase64(document.code.text.value);">
</td></tr>
<tr><tdalign=center>
<inputvalue="Encode"type=buttononclick="document.code.text.value=encodeHex(document.code.text.value);">
</td><tdalign=center>
Hex
</td><tdalign=center>
<inputvalue="Decode"type=buttononclick="document.code.text.value=decodeHex(document.code.text.value);">
</td></tr>
<tr><tdalign=center>
</td><tdalign=center>
<inputtype=resetvalue=Clear>
</td><tdalign=center>
</td></tr>
</table>
</form>
<hr>
Base64encode/decodewasportedfroma<ahref="http://ostermiller.org/utils/Base64.html">JavaBase64encoder/decoder</a>.<br>
Base64encode/decodewasportedto<ahref="http://ostermiller.org/base64_actionscript.html">MacromediaActionscript</a>.<br>
<h3>License</h3>
<p>Thisprogramisfreesoftware;youcanredistributeitand/ormodifyit
underthetermsoftheGNUGeneralPublicLicenseaspublishedbytheFree
SoftwareFoundation;eitherversion2oftheLicense,or(atyouroption)
anylaterversion.</p>
<p>Thisprogramisdistributedinthehopethatitwillbeuseful,
butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyofMERCHANTABILITY
orFITNESSFORAPARTICULARPURPOSE.Seethe
<ahref="http://www.gnu.org/copyleft/gpl.html">GNU
GeneralPublicLicense</a>formoredetails.</p>
<divstyle="padding:0.2cm;"><ahref="http://ostermiller.org/calc/">Moreconverters,calculators,andotherJavaScriptgoodies</a></div>
<divstyle="padding:0.2cm;text-align:right;"><ahref="http://ostermiller.org/">ostermiller.org</a>(<ahref="http://ostermiller.org/siteindex.html">siteindex</a>)</div>
<divstyle="padding:0.2cm;"><p>Copyright<ahref="http://ostermiller.org/contact.pl?regarding=JavaScript+Encoding"class=mail>StephenOstermiller</a>2003-2006</p></div>
</body>
</html>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章