【发布时间】:2022-09-28 01:11:24
【问题描述】:
我正在寻找一种有效的方法来使用相同的密钥对数字进行加密和破译。 这不用于加密或加密任何东西,因此它不需要是安全的。
我有一个唯一的号码,我总是希望从密码中得到相同的结果。密码不应太长(超过 6 个字符)。 我确实关心速度,因为我将制作大约 1000 个/毫秒的密码。
我将寻找密码的最大数字是 100,000,000 并且考虑到字母数字 = 26 个小写字母 + 26 个大写字母和 10 个数字的 6 个字符,大约 5.680 * 10^9 组合就足够了。
伪代码示例:
let num_to_cypher = 1;
let cypher = cypher_this_number(num_to_cypher); // ==> Ax53iw
let decypher = decypher_this_number(cypher); // ==> 1
let num_to_cypher_ex_2 = 12
let cypher_ex_2 = cypher_this_number(num_to_cypher_ex_2); // ==> 2R5ty6
let decypher_ex_2 = decypher_this_number(cypher_ex_2); // ==> 1
编辑1:
我本可以做类似下面的事情,但我不能在这个例子中定义密码的长度,我不关心加密,所以我可以更快地进行。
function encrypt(text){
let cipher = crypto.createCipher(\'aes128\',\'d6F3Efeq\')
let crypted = cipher.update(text,\'utf8\',\'hex\')
crypted += cipher.final(\'hex\');
return crypted;
}
function decrypt(text){
let decipher = crypto.createDecipher(\'aes128\',\'d6F3Efeq\')
let dec = decipher.update(text,\'hex\',\'utf8\')
dec += decipher.final(\'utf8\');
return dec;
}
标签: node.js cryptography hex