共计 1722 个字符,预计需要花费 5 分钟才能阅读完成。
JS 混同加密是一种将 JavaScript 代码进行混同和加密的技术,旨在使代码更难以浏览和了解,从而减少破解难度。控制流平坦化是其中一种罕用的混同技术,它能够使代码的管制流程变得非常复杂,减少代码的可读性和可维护性的难度。上面是一个应用控制流平坦化进行混同加密的示例代码:
javascriptCopy codefunction encrypt(text) {
var encrypted = "";
for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 10;
encrypted += String.fromCharCode(newCode);
}
return encrypted;
}
function decrypt(encrypted) {
var decrypted = "";
for (var i = 0; i < encrypted.length; i++) {var code = encrypted.charCodeAt(i);
var newCode = code - 10;
decrypted += String.fromCharCode(newCode);
}
return decrypted;
}
var input = "Hello World!";
var encrypted = encrypt(input);
var decrypted = decrypt(encrypted);
console.log(decrypted);
以上代码能够加密和解密一个字符串,然而它非常容易被破解,因为加密和解密的过程都是固定的,没有任何随机性和变动。为了减少代码的破解难度,咱们能够应用控制流平坦化技术,如下所示:
javascriptCopy codefunction encrypt(text) {
var encrypted = "";
var a = Math.floor(Math.random() * 10);
if (a == 0) {for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 10;
encrypted += String.fromCharCode(newCode);
}
} else if (a == 1) {for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 20;
encrypted += String.fromCharCode(newCode);
}
} else if (a == 2) {for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 30;
encrypted += String.fromCharCode(newCode);
}
} else if (a == 3) {for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 40;
encrypted += String.fromCharCode(newCode);
}
} else if (a == 4) {for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 50;
encrypted += String.fromCharCode(newCode);
}
} else if (a == 5) {for (var i = 0; i < text.length; i++) {var code = text.charCodeAt(i);
var newCode = code + 60;
encrypted += String.fromCharCode(newCode);
}
} else if (a == 6) {for (var i = 0; i < text.length; i++) {
jsjiami.com
如果您对文章内容有不同认识, 或者疑难,欢送到评论区留言,或者私信我都能够。
也能够到上方网站,底部有我联系方式详谈
如遇本人源码加密后没备份,能够找咱们解决解出复原源码,任何加密都能够。
正文完