JavaScript Base64HEX EncoderDecoder. (ZT)

xiaoxiao2021-03-06  126

Base64 and Hex Encoding and Decoding </ title> <meta name = "Description" content = "Encodes or decodes data in Base64 or Hex using client side JavaScript."> <Meta name = "Keywords "Content =" Encode, Decode, Base64, Base 64, JavaScript "> <script language = javaScript type =" text / javascript "> <! - var end_of_input = -1;</p> <p>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', ' ', '/');</p> <p>Var reversebase64chars = new array (); for (var i = 0; i <base64chars.length; i ) {reverseBase64chars [base64chars [i]] = i;}</p> <p>var base64Str; var base64Count; function setBase64Str (str) {base64Str = str; base64Count = 0;} (! base64Str) function readBase64 () {if 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 " ] << 4) & 0x30)]); result = ('='); result = ('='); done = true;} linecount = 4; if (linecount> = 76) {Result = ('/ n'); linecount = 0;}} Return Result;</p> <p>} 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;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} function NTOS (n) {n = n.tostring (16); if (n.Length == 1) n = "0 " n; n ="% " n; return unescape (n);}</p> <p>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;</p> <p>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 }</p> <p>Function EncodeHex (STR) {var result = ""; for (var i = 0; i <str.length; i ) {results = Pad (tohex (Str.Charcodeat (i) & 0xff), 2, '0') } Return result;}</p> <p>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) {results = NTOS (Eval ('0x' nextchar)); Nextchar = "";}} Return Result;} // -> </ script> </ head> <body> <form name = code οnsubmit = "Return false ()> <textarea name = text style = 'Width: 100 %; Height: 75%; '> Enter text to encode or decode here. </ textarea> <table> <tr> <TD align = center> <input value = "encode" type = button οnclick = "Document.code. Text.Value = Encodebase64 (Document.code.Text.Value); "> </ td> <td align = center> base 64 </ td> <td align = center> <input value =" decode "type = button οnclick = "Document.code.text.Value = decode.text.value;"> </ td> </ tr> <tr> <td align = center> <input value = "encode" type = button οnclick = "Document.code.text.value = EncodeHex (Document.code.Text.Value);"> </ td> <TD align = center> HEX </ td> <TD align = center> <input value = " Di Ecode "type = button οnclick =" Document.code.text.value = decodeHex (Document.code.Text.Value); "> </ td> </ tr> <tr> <td align = center> </ td> <TD align = center> <input type = reset value = clear> </ td> <td align = center> </ td> </ tr> </ table> <</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-125430.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="125430" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.048</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'i6KVjXDGlnconV7brcAJLkXscrIa5JBkH3MmZksUL48otb90ExIeQ2MNlilGvLuEOQ8T96_2BHD7WcdvBgyUFlCw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>