【问题标题】:What is the name of this cryptography algorithm?这种加密算法的名称是什么?
【发布时间】: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


【解决方案1】:

密码本身(通过 XOR 将密钥流与纯文本组合)称为 Vernam Cipher(以其发明者 Gilbert Vernam 命名)。

我不知道这种创建密钥流的特定方法的名称,尽管它所属的组有许多众所周知的名称,例如“bad”、“awful”和“broken”。

这个例子看起来特别有问题。如果(例如)modincr 都是素数,您至少要在重复之前增加密钥流中的字符数。照原样,它会在很短的时间后重复(这让攻击者可以使用更少的密文找到密钥流)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 2011-02-10
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多