zoukankan      html  css  js  c++  java
  • 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)
                }
            }
  • 相关阅读:
    去除网页图片缝隙
    只有定位的盒子有z-index
    clearfix
    2018CSS特效集锦牛逼
    c#spinLock使用
    redis 五种数据结构详解(string,list,set,zset,hash)
    C# StackExchange.Redis 用法总结
    Markdown 编辑器
    C# Task任务详解及其使用方式
    MongoDB学习笔记——MongoDB 连接配置
  • 原文地址:https://www.cnblogs.com/gavin007/p/7908724.html
Copyright © 2011-2022 走看看