function rot13(str) {
// todo 97和122 对应的Unicode编码
var newarr = [];
for (var i = 0; i < str.length; i++) {
// console.log(str.charCodeAt(i));
if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91) { //大写字母区间 ascii码
if (str.charCodeAt(i) > 77){
// 后13个字母,减去13
newarr.push(String.fromCharCode(str.charCodeAt(i) - 13));
}else{
// 前13个字母,加上13
newarr.push(String.fromCharCode(str.charCodeAt(i) + 13));
}
} else if (str.charCodeAt(i) > 96 && str.charCodeAt(i) < 123){ //小写字母区间 ascii码
if (str.charCodeAt(i) > 109) {
newarr.push(String.fromCharCode(str.charCodeAt(i) - 13));
} else {
newarr.push(String.fromCharCode(str.charCodeAt(i) + 13));
}
}else{
newarr.push(str.charAt(i)); // 非字母形式的字符,直接跳过,存入数组newarr中
}
}
var newstr = newarr.join("");
return newstr;
}
/**
* 生成随机字符
*/
function randomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
var maxPos = $chars.length;
var pwd = '';
var i = 0;
for (i; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function createPwd(pwd){
//拼一个随机字符
var before = randomString(1);
var after = randomString(1);
var newstr = before + rot13(pwd) + after;
// console.log(newstr)
return newstr;
}function rot13(str) {
// todo 97和122 对应的Unicode编码
var newarr = [];
for (var i = 0; i < str.length; i++) {
// console.log(str.charCodeAt(i));
if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91) { //大写字母区间 ascii码
if (str.charCodeAt(i) > 77){
// 后13个字母,减去13
newarr.push(String.fromCharCode(str.charCodeAt(i) - 13));
}else{
// 前13个字母,加上13
newarr.push(String.fromCharCode(str.charCodeAt(i) + 13));
}
} else if (str.charCodeAt(i) > 96 && str.charCodeAt(i) < 123){ //小写字母区间 ascii码
if (str.charCodeAt(i) > 109) {
newarr.push(String.fromCharCode(str.charCodeAt(i) - 13));
} else {
newarr.push(String.fromCharCode(str.charCodeAt(i) + 13));
}
}else{
newarr.push(str.charAt(i)); // 非字母形式的字符,直接跳过,存入数组newarr中
}
}
var newstr = newarr.join("");
return newstr;
}
/**
* 生成随机字符
*/
function randomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
var maxPos = $chars.length;
var pwd = '';
var i = 0;
for (i; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function createPwd(pwd){
//拼一个随机字符
var before = randomString(1);
var after = randomString(1);
var newstr = before + rot13(pwd) + after;
// console.log(newstr)
return newstr;
}
encrypt_pwd.js
最新推荐文章于 2022-08-18 22:50:50 发布