• js 异或加密


         // 按位异或 加密
            var posNo = 'C0041710190002'
            // 特殊字符不进行 与或 加密 (因为A,a,Z,z,转换后会变成符号,不方面用户输入,也可自己定义)
            var special = {
                'A': 1,
                'a': 1,
                'Z': 1,
                'z': 1
            }

            console.log('xor: ', bitEncrypt(posNo))  // xor:  B1150601081113

            function bitEncrypt (data) {
                var data = data || ''
                var arr = data.split('')
                
                var result = arr.map(function (item) {
                    if (!special[item]) {
                        return xor(item)
                    } else {
                        return item
                    }
                })
                return result.join('')
            }

            function xor(msg) {
                var isNum = /[0-9]/.test(msg)
                if (isNum) {
                    return +msg ^ 1
                } else {
                    var num10 = msg.charCodeAt()
                    var numXOR = num10 ^ 1
                    return String.fromCharCode(numXOR)
                }
            }
  • 相关阅读:
    STL之vector
    [洛谷P3942] 将军令
    [洛谷P2127] 序列排序
    [USACO07FEB]新牛棚Building A New Barn
    [洛谷P1120] 小木棍 [数据加强版]
    [洛谷P1438] 无聊的数列
    我的Emacs配置
    [CQOI2015]任务查询系统
    可持久化数组入门
    学习openstack(六)
  • 原文地址:https://www.cnblogs.com/gavin007/p/7908724.html
Copyright © 2020-2023  润新知