function xorEncrypt(plaintext, key) {
let encrypted = '';
for (let i = 0; i < plaintext.length; i++) {
encrypted += String.fromCharCode(plaintext.charCodeAt(i) ^ key.charCodeAt(i % key.length));
}
return btoa(encrypted);
}
let key = 'gotojiam';
let plaintext = 'https://www.baidu.com/';
let encrypted = xorEncrypt(plaintext, key);
console.log(encodeURIComponent(encrypted));
//DxsAHxlTTkIQGANBCAgICRJBFwAHRg==
// 解密
function xorDecrypt(encrypted, key) {
let decoded = atob(encrypted);
let decrypted = '';
for (let i = 0; i < decoded.length; i++) {
decrypted += String.fromCharCode(decoded.charCodeAt(i) ^ key.charCodeAt(i % key.length));
}
return decrypted;
}
let key = 'gotojiam';
let encrypted = 'DxsAHxlTTkIQGANBCAgICRJBFwAHRg==';
let decrypted = xorDecrypt(encrypted, key);
console.log(decrypted); 简单的对称 XOR 加密/解密
杂七杂八 · 2025-11-11
上一篇:系统下载
下一篇:没有了
评论