About encrypting and decrypting Base64 and URLs and Hex Encoding and Decoding_ scripts plus decryption

Source: Internet
Author: User
Tags base64 base64 encode javascript urlencode urlencode
Today want to change the style of Discuz forum, who knows the download style file, found unexpectedly is through the Base64 encrypted
Kobayashi has recommended a decrypted page, extract the code as follows:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>base64 and URLs and Hex Encoding and decoding</title>
<meta name= "description" content= "encodes or decodes data in Base64 or URL encoding using client side JavaScript"/>
<meta name= "keywords" content= base64, Base, UrlEncode, UrlDecode, Hexencode, hex encode, Hexdecode hex, decode, Java  Script base64, JavaScript base, JavaScript urlencode, JavaScript urldecode, JavaScript hexencode, JavaScript hexdecode " />
<link rel= "shortcut icon" href= "Http://ostermiller.org/favicon.ico" type= "Image/x-icon"/>
<script language=javascript type= "Text/javascript" >
<!--
function UrlDecode (str) {
Str=str.replace (New RegExp (' \\+ ', ' g '), ');
return unescape (str);
}
function UrlEncode (str) {
Str=escape (str);
Str=str.replace (New RegExp (' \\+ ', ' g '), '%2b ');
Return Str.replace (New RegExp ('%20 ', ' g '), ' + ');
}
var end_of_input =-1;
var base64chars = new Array (
' 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 ', ' + ', '/'
);
var reversebase64chars = new Array ();
for (Var i=0 i < base64chars.length; i++) {
Reversebase64chars[base64chars[i]] = i;
}
var base64str;
var Base64count;
function Setbase64str (str) {
Base64str = str;
Base64count = 0;
}
function ReadBase64 () {
if (!BASE64STR) return end_of_input;
if (Base64count >= base64str.length) return end_of_input;
var c = base64str.charcodeat (Base64count) & 0xFF;
base64count++;
return C;
}
function EncodeBase64 (str) {
Setbase64str (str);
var result = ';
var inbuffer = new Array (3);
var linecount = 0;
var done = 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;
}
}
return result;
}
function ReadReverseBase64 () {
if (!BASE64STR) return end_of_input;
while (true) {
if (Base64count >= base64str.length) return end_of_input;
var nextcharacter = Base64str.charat (Base64count);
base64count++;
if (Reversebase64chars[nextcharacter]) {
return Reversebase64chars[nextcharacter];
}
if (Nextcharacter = = ' A ') return 0;
}
return end_of_input;
}
function Ntos (n) {
N=n.tostring (16);
if (n.length = = 1) n= "0" +n;
n= "%" +n;
return unescape (n);
}
function DecodeBase64 (str) {
Setbase64str (str);
var result = "";
var inbuffer = new Array (4);
var done = 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;
}
}
return result;
}
var digitarray = new Array (' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' d ', ' e ', ' f ');
function Tohex (n) {
var result = '
var start = true;
for (var i=32; i>0;) {
i-=4;
var digit = (n>>i) & 0xf;
if (!start | | digit!= 0) {
start = false;
result = Digitarray[digit];
}
}
Return (result== '? ') 0 ': result);
}
function pad (str, len, pad) {
var result = str;
for (var i=str.length; i<len; i++) {
result = pad + result;
}
return result;
}
function Encodehex (str) {
var result = "";
for (var i=0; i<str.length; i++) {
Result + + pad (Tohex (str.charcodeat (i) &0xff), 2, ' 0 ');
}
return result;
}
function Decodehex (str) {
str = str.replace (new RegExp ("s/[^0-9a-za-z]//g"));
var result = "";
var nextchar = "";
for (var i=0; i<str.length; i++) {
Nextchar + + Str.charat (i);
if (nextchar.length = = 2) {
result = Ntos (eval (' 0x ' +nextchar));
Nextchar = "";
}
}
return result;
}
--></script>
<body>
<form Name=code onsubmit= "return False ()" >
<textarea name=text style= ' width:100%;height:75% ' onfocus= ' if (this.value== "Enter text to encode or decode here.") {this.value= "";} ' >enter text to encode or decode here.</textarea>
<table>
&LT;TR&GT;&LT;TD align=center>
<input value= "Encode" Type=button onclick= "Document.code.text.value=urlencode (document.code.text.value);" >
&LT;/TD&GT;&LT;TD align=center>
Url
&LT;/TD&GT;&LT;TD align=center>
<input value= "Decode" Type=button onclick= "Document.code.text.value=urldecode (document.code.text.value);" >
</td></tr>
&LT;TR&GT;&LT;TD align=center>
<input value= "Encode" Type=button onclick= "document.code.text.value=encodebase64 (document.code.text.value);" >
&LT;/TD&GT;&LT;TD align=center>
Base 64
&LT;/TD&GT;&LT;TD align=center>
<input value= "Decode" Type=button onclick= "document.code.text.value=decodebase64 (document.code.text.value);" >
</td></tr>
&LT;TR&GT;&LT;TD align=center>
<input value= "Encode" Type=button onclick= "Document.code.text.value=encodehex (document.code.text.value);" >
&LT;/TD&GT;&LT;TD align=center>
Hex
&LT;/TD&GT;&LT;TD align=center>
<input value= "Decode" Type=button onclick= "Document.code.text.value=decodehex (document.code.text.value);" >
</td></tr>
&LT;TR&GT;&LT;TD align=center>
&LT;/TD&GT;&LT;TD align=center>
<input Type=reset value=clear>
&LT;/TD&GT;&LT;TD align=center>
</td></tr>
</table>
</form>
Base64 Encode/decode is ported from a <a href= "http://ostermiller.org/utils/Base64.html" >java Base64 Decoder</a>.<br>
Base64 Encode/decode is ported to <a href= "http://ostermiller.org/base64_actionscript.html" >macromedia Actionscript</a>.<br>
<p>this are free software; You can redistribute it and/or modify it
Under the terms of the GNU general public License as published by the
Software Foundation; Either version 2 of the License, or (at your option)
Any later version.</p>
<p>this program are distributed in the hope that it would be useful,
but without any WARRANTY; Without even the implied warranty of merchantability
or FITNESS for A particular purpose. The
<a href= "http://www.gnu.org/copyleft/gpl.html" >gnu
General public license</a> for more details.</p>
<div style= "padding:0.2cm;" ><a href= "http://ostermiller.org/calc/" >more converters, calculators, and other JavaScript goodies</a> </div>
<div style= "padding:0.2cm;text-align:right;" ><a href= "http://ostermiller.org/" >ostermiller.org</a> (<a href= "http://ostermiller.org/") siteindex.html ">site index</a>" </div>
<div style= "padding:0.2cm;" ><p>copyright <a href= "http://ostermiller.org/contact.pl?regarding=JavaScript+Encoding" Class=mail >stephen ostermiller</a> 2003-2006</p></div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.