【发布时间】:2018-02-14 20:03:12
【问题描述】:
我在下面的“the_cipher_decipher_func”中找到了加密算法:
#include <string>
#include <iostream>
#include <algorithm>
std::string cipher_decipher(const std::string& src, char mask, const char incr, const char mod)
{
const auto the_cipher_decipher_func = [&](const char c)
{
mask = (mask + incr) % mod;
return static_cast<char>(c ^ mask);
};
auto tgt = std::string{};
std::transform(src.cbegin(), src.cend(), std::back_inserter(tgt), the_cipher_decipher_func);
return tgt;
}
int main(int argc, char* argv[])
{
if (argc < 2)
return 1;
auto source = std::string{argv[1]};
const char incr = 12; // arbitrary
const char mod = 50; // arbitrary
const char initial_mask = mod / incr; // arbitrary, but lower than "mod".
auto mask_cipher = initial_mask;
auto ciphered = cipher_decipher(source, mask_cipher, incr, mod);
auto mask_decipher = initial_mask;
auto deciphered = cipher_decipher(ciphered, mask_decipher, incr, mod);
std::cout
<< "source: " << source << std::endl
<< "ciphered: " << ciphered << std::endl
<< "deciphered: " << deciphered << std::endl
;
return 0;
}
这似乎是 XOR 和增量密钥的混合。但是,有人可以确定这种加密算法的确切来源吗?
【问题讨论】:
-
你在哪里找到的?
-
"Cesar cipher" 有效吗?一个老...
-
我怀疑它本身有一个名字。它只是一个凯撒密码 + XOR 密码。
-
@user463035818,我在我的一个客户的源代码中找到了这个算法。不幸的是,他们失去了任何关于它的参考。我用计算出的键表查看了Vigenère cipher。这是我能找到的更近的地方。
-
我投票结束这个问题作为题外话,因为认真。
标签: c++ encryption cryptography xor