首页 > 其他分享 >加密,解密 样例

加密,解密 样例

时间:2023-06-11 13:34:00浏览次数:29  
标签:index 加密 val ++ pow 样例 解密 && position

 

 

 

加密

function _compress(e, t, n) {
                    if (null == e)
                        return "";
                    var r, o, i, a = {}, s = {}, c = "", u = "", l = "", d = 2, f = 3, p = 2, h = [], v = 0, m = 0;
                    for (i = 0; i < e.length; i += 1)
                        if (c = e.charAt(i),
                        Object.prototype.hasOwnProperty.call(a, c) || (a[c] = f++,
                        s[c] = !0),
                        u = l + c,
                        Object.prototype.hasOwnProperty.call(a, u))
                            l = u;
                        else {
                            if (Object.prototype.hasOwnProperty.call(s, l)) {
                                if (l.charCodeAt(0) < 256) {
                                    for (r = 0; r < p; r++)
                                        v <<= 1,
                                        m == t - 1 ? (m = 0,
                                        h.push(n(v)),
                                        v = 0) : m++;
                                    for (o = l.charCodeAt(0),
                                    r = 0; r < 8; r++)
                                        v = v << 1 | 1 & o,
                                        m == t - 1 ? (m = 0,
                                        h.push(n(v)),
                                        v = 0) : m++,
                                        o >>= 1
                                } else {
                                    for (o = 1,
                                    r = 0; r < p; r++)
                                        v = v << 1 | o,
                                        m == t - 1 ? (m = 0,
                                        h.push(n(v)),
                                        v = 0) : m++,
                                        o = 0;
                                    for (o = l.charCodeAt(0),
                                    r = 0; r < 16; r++)
                                        v = v << 1 | 1 & o,
                                        m == t - 1 ? (m = 0,
                                        h.push(n(v)),
                                        v = 0) : m++,
                                        o >>= 1
                                }
                                0 == --d && (d = Math.pow(2, p),
                                p++),
                                delete s[l]
                            } else
                                for (o = a[l],
                                r = 0; r < p; r++)
                                    v = v << 1 | 1 & o,
                                    m == t - 1 ? (m = 0,
                                    h.push(n(v)),
                                    v = 0) : m++,
                                    o >>= 1;
                            0 == --d && (d = Math.pow(2, p),
                            p++),
                            a[u] = f++,
                            l = String(c)
                        }
                    if ("" !== l) {
                        if (Object.prototype.hasOwnProperty.call(s, l)) {
                            if (l.charCodeAt(0) < 256) {
                                for (r = 0; r < p; r++)
                                    v <<= 1,
                                    m == t - 1 ? (m = 0,
                                    h.push(n(v)),
                                    v = 0) : m++;
                                for (o = l.charCodeAt(0),
                                r = 0; r < 8; r++)
                                    v = v << 1 | 1 & o,
                                    m == t - 1 ? (m = 0,
                                    h.push(n(v)),
                                    v = 0) : m++,
                                    o >>= 1
                            } else {
                                for (o = 1,
                                r = 0; r < p; r++)
                                    v = v << 1 | o,
                                    m == t - 1 ? (m = 0,
                                    h.push(n(v)),
                                    v = 0) : m++,
                                    o = 0;
                                for (o = l.charCodeAt(0),
                                r = 0; r < 16; r++)
                                    v = v << 1 | 1 & o,
                                    m == t - 1 ? (m = 0,
                                    h.push(n(v)),
                                    v = 0) : m++,
                                    o >>= 1
                            }
                            0 == --d && (d = Math.pow(2, p),
                            p++),
                            delete s[l]
                        } else
                            for (o = a[l],
                            r = 0; r < p; r++)
                                v = v << 1 | 1 & o,
                                m == t - 1 ? (m = 0,
                                h.push(n(v)),
                                v = 0) : m++,
                                o >>= 1;
                        0 == --d && (d = Math.pow(2, p),
                        p++)
                    }
                    for (o = 2,
                    r = 0; r < p; r++)
                        v = v << 1 | 1 & o,
                        m == t - 1 ? (m = 0,
                        h.push(n(v)),
                        v = 0) : m++,
                        o >>= 1;
                    for (; ; ) {
                        if (v <<= 1,
                        m == t - 1) {
                            h.push(n(v));
                            break
                        }
                        m++
                    }
                    return h.join("")
                };

var n = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$';

_compress(
    '{"5":{"p":2,"pp":25}}',
     6, (function(e) {
                        return n.charAt(e)
                    }
                    )
)

 

 

 


 

 

解密

 

function _decompress(t, n, r) {
                    var o, i, a, s, c, u, l, d = [], f = 4, p = 4, h = 3, v = "", m = [], g = {
                        val: r(0),
                        position: n,
                        index: 1
                    };
                    for (o = 0; o < 3; o += 1)
                        d[o] = o;
                    for (a = 0,
                    c = Math.pow(2, 2),
                    u = 1; u != c; )
                        s = g.val & g.position,
                        g.position >>= 1,
                        0 == g.position && (g.position = n,
                        g.val = r(g.index++)),
                        a |= (s > 0 ? 1 : 0) * u,
                        u <<= 1;
                    switch (a) {
                    case 0:
                        for (a = 0,
                        c = Math.pow(2, 8),
                        u = 1; u != c; )
                            s = g.val & g.position,
                            g.position >>= 1,
                            0 == g.position && (g.position = n,
                            g.val = r(g.index++)),
                            a |= (s > 0 ? 1 : 0) * u,
                            u <<= 1;
                        l = e(a);
                        break;
                    case 1:
                        for (a = 0,
                        c = Math.pow(2, 16),
                        u = 1; u != c; )
                            s = g.val & g.position,
                            g.position >>= 1,
                            0 == g.position && (g.position = n,
                            g.val = r(g.index++)),
                            a |= (s > 0 ? 1 : 0) * u,
                            u <<= 1;
                        l = e(a);
                        break;
                    case 2:
                        return ""
                    }
                    for (d[3] = l,
                    i = l,
                    m.push(l); ; ) {
                        if (g.index > t)
                            return "";
                        for (a = 0,
                        c = Math.pow(2, h),
                        u = 1; u != c; )
                            s = g.val & g.position,
                            g.position >>= 1,
                            0 == g.position && (g.position = n,
                            g.val = r(g.index++)),
                            a |= (s > 0 ? 1 : 0) * u,
                            u <<= 1;
                        switch (l = a) {
                        case 0:
                            for (a = 0,
                            c = Math.pow(2, 8),
                            u = 1; u != c; )
                                s = g.val & g.position,
                                g.position >>= 1,
                                0 == g.position && (g.position = n,
                                g.val = r(g.index++)),
                                a |= (s > 0 ? 1 : 0) * u,
                                u <<= 1;
                            d[p++] = e(a),
                            l = p - 1,
                            f--;
                            break;
                        case 1:
                            for (a = 0,
                            c = Math.pow(2, 16),
                            u = 1; u != c; )
                                s = g.val & g.position,
                                g.position >>= 1,
                                0 == g.position && (g.position = n,
                                g.val = r(g.index++)),
                                a |= (s > 0 ? 1 : 0) * u,
                                u <<= 1;
                            d[p++] = e(a),
                            l = p - 1,
                            f--;
                            break;
                        case 2:
                            return m.join("")
                        }
                        if (0 == f && (f = Math.pow(2, h),
                        h++),
                        d[l])
                            v = d[l];
                        else {
                            if (l !== p)
                                return null;
                            v = i + i.charAt(0)
                        }
                        m.push(v),
                        d[p++] = i + v.charAt(0),
                        i = v,
                        0 == --f && (f = Math.pow(2, h),
                        h++)
                    }
                };



var e = String.fromCharCode
              , t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
              , n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$"
              , r = {};


function o(e, t) {
                if (!r[e]) {
                    r[e] = {};
                    for (var n = 0; n < e.length; n++)
                        r[e][e.charAt(n)] = n
                }
                return r[e][t]
            };


function decompressFromEncodedURIComponent(e) {
                    return (e = e.replace(/ /g, "+"),
                    _decompress(e.length, 32, (function(t) {
                        return o(n, e.charAt(t))
                    }
                    )))
                };





                let aa = decompressFromEncodedURIComponent('N4IgrCBcoA5QTAGhDOl5gL6aA');


                console.log(aa);

 

标签:index,加密,val,++,pow,样例,解密,&&,position
From: https://www.cnblogs.com/angdh/p/17472842.html

相关文章

  • tink google 加密安全实践的框架
    tink是google多年加密实践的框架,提供了安全的加密处理方法,可以简化不少我们的加密处理参考使用publicstaticvoidmain(String[]args)throwsGeneralSecurityException,IOException{AeadConfig.register();//1.Generatethekeymaterial.KeysetHandlekeysetHandle=Key......
  • .locked加密勒索数据库级别恢复---惜分飞
    联系:手机/微信(+8617813235971)QQ(107644445)标题:.locked加密勒索数据库级别恢复作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]有客户数据库被加密成.locked结尾的扩展名,数据库无法正常使用对应的READ_ME1.html文件中信息类似:s......
  • DES加密算法及Python实现
    一、DES加密算法原理DES加密算法是一种对称密钥的块加密算法,1976年成为美国联邦标准。其加密流程如下:密钥的生成:将64位密钥按照置换选择1表进行置换,得到56位的密钥,并分成左右两部分各28位。然后使用16个不同的演算法对密钥进行处理,生成16个48位子密钥。明文分组:将明文分成64位的块,......
  • Python实现字符串与指定密钥循环异或加解密
    异或运算在很多密码学算法中都有不同程度的应用,其运算特定在于一个数和另一个数连续异或两次仍得到原来的数。在实际使用中,因为要加密的信息和所使用的密钥在大多数情况下是不等长的,所以经常需要循环使用密钥。defcrypt1(source,key):'''source是要加密或解密的字符串,key是......
  • php7.2+实现3des加解密
    //加密functionencrypt($str,$key){$data=openssl_encrypt($str,'des-ede3',$key,OPENSSL_RAW_DATA);$data=base64_encode($data);return$data;} echoencrypt('test','1234567890');//输出:gG4H......
  • 解密香港主机:提升你网站速度的秘密武器!
    在如今高速发展的互联网时代,网站速度对于用户体验和搜索引擎排名至关重要。当用户访问一个网站时,如果加载时间过长,他们很可能会感到沮丧并放弃继续浏览。此外,搜索引擎也更倾向于将速度较快的网站排名靠前。为了解决这个问题,许多网站管理员正在寻找提升网站速度的方法。而香港主......
  • 密码学(5):常见非对称加密算法
    叨两句密码系列文章,是对接第三方接口时接触到加解密,但是知识体系较乱。希望能整理常见证书、密钥、加解密方式这方面知识,用于简单理解和快速区分。有些缺漏和待补充,后续慢慢完善。有任何问题欢迎提出,便于及时修正1.RSA算法1.介绍2.依赖的数学原理1)将两个大素数相乘十分容......
  • 77 加密一个值 +5 取余数 倒序
    正确的是二次倒序packagecom.fqs.test;importjava.util.Scanner;publicclasshello{publicstaticvoidmain(String[]args){//加密传输1983//每位上加5(1+5=6)%10取余9+5=148+5=133+5=8//对10取余//颠倒顺序输出......
  • C#.NET Framework RSA 公钥加密 私钥解密 ver:20230609
    C#.NETFrameworkRSA公钥加密私钥解密ver:20230609 环境说明:.NETFramework4.6的控制台程序 。 .NETFramework 对于RSA的支持:1. .NETFramework内置只支持XML格式的私钥/公钥。如果要用PKCS1,PKCS8格式的,要用到三方库BouncyCastle。2..NET中默认加密算法为......
  • CAPL 脚本加密
    点开CAPL编辑器点击FILE选择生成加密文件  在路径中删除源CAPL文件。生成的加密文件 ......