zoukankan      html  css  js  c++  java
  • JavaScript Base64 解密方法

        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(a) {
    base64Str = a;
    base64Count = 0
    }
    function readReverseBase64() {
    if (!base64Str) {
    return END_OF_INPUT
    }
    while (true) {
    if (base64Count >= base64Str.length) {
    return END_OF_INPUT
    }
    var a = base64Str.charAt(base64Count);
    base64Count++;
    if (reverseBase64Chars[a]) {
    return reverseBase64Chars[a]
    }
    if (a == "A") {
    return 0
    }
    }
    return END_OF_INPUT
    }
    function ntos(a) {
    a = a.toString(16);
    if (a.length == 1) {
    a = "0" + a
    }
    a = "%" + a;
    return unescape(a)
    }
    function decodeBase64(d) {
    setBase64Str(d);
    var a = "";
    var c = new Array(4);
    var b = false;
    while (!b && (c[0] = readReverseBase64()) != END_OF_INPUT && (c[1] = readReverseBase64()) != END_OF_INPUT) {
    c[2] = readReverseBase64();
    c[3] = readReverseBase64();
    a += ntos((((c[0] << 2) & 255) | c[1] >> 4));
    if (c[2] != END_OF_INPUT) {
    a += ntos((((c[1] << 4) & 255) | c[2] >> 2));
    if (c[3] != END_OF_INPUT) {
    a += ntos((((c[2] << 6) & 255) | c[3]))
    } else {
    b = true
    }
    } else {
    b = true
    }
    }
    return a
    }

    BASE64 解密代码...

    记录以作备用

  • 相关阅读:
    sql 存储过程
    Chrome系列 Failed to load resource: net::ERR_CACHE_MISS
    oledb 操作 excel
    [转]基于SQL脚本将数据库表及字段提取为C#中的类
    Ul li 竖排 菜单
    JS判断checkbox至少选择一项
    JS 字符串转日期格式 日期格式化字符串
    setInterval 实时驱动界面改变
    Let's Format Css Documents
    Web颜色搭配
  • 原文地址:https://www.cnblogs.com/hanf/p/2367928.html
Copyright © 2011-2022 走看看