javascript - Javascript中的XOR密码解密
问题描述
我有一个必须解码的 base64 字符串,即AwELBwc=
. 使用给我的 XOR 密码密钥,即26364
,我必须对字符串进行解码以获得一个我已经知道的数字 ( 7813
)。
这将如何在 Javascript 中完成,您在其中获取一个 base64 编码的字符串,通过具有已知密钥的 XOR 密码运行它,然后输出结果?
解决方案
这段代码应该做你想做的事:
function base64ToArray(base64String) {
var bstr = atob(base64String);
var bytes = [];
for (var i = 0; i < bstr.length; i++) {
bytes.push(bstr.charCodeAt(i));
}
return bytes;
}
let key = [2,6,3,6,4];
let cipherTextBase64 = 'AwELBwc=';
let cipherTextBytes = base64ToArray(cipherTextBase64);
let result = key.map((value,index) => {
return value ^ cipherTextBytes[index];
});
document.getElementById('output').innerHTML = 'Result: ' + result.join();
console.log('Result: ', result);
<div id="output">
</div>
推荐阅读
- html - AWS cloundfront 视频加载速度
- excel - 使用选择/vlookup 函数在基于用户表单输入的查找表之间进行选择时遇到错误
- mongodb - 当你有一个索引使用 `min` 和 `max` 比 `$gte` 和 `$lt` 快?为什么?
- python - 元素长度调整大小(硒,python)
- javascript - Javascript:使用动态列名执行 SQL 查询
- compiler-errors - SPARC-RTEMS5-GCC 忽略或找不到库
- python-3.x - 如何克服无法将字符串转换为浮点数?
- android - 在 Android 中为芯片设置边框颜色
- prolog - 如果变量未实例化,则调用不同的谓词
- angular - 角度延迟加载会破坏骨架加载动画