小编cea*_*sif的帖子

为什么我可以使用一个DES密钥加密数据并成功解密另一个DES密钥?

我尝试使用pyDes和Crypto.Cipher.DES模块实现DES算法.我发现了一个问题,当我用82514145密钥加密然后解密密码93505044我可以检索解密的文本.我发现256个键表现得像这样.这违反了密码学.我的代码如下:

    from Crypto.Cipher import DES
    plain_text = 'asdfghij'
    print 'plain Text: ', plain_text

    des = DES.new('82514145', DES.MODE_ECB)
    cipher_text = des.encrypt(plain_text)
    print 'the cipher text is ', cipher_text

    des = DES.new('93505044', DES.MODE_ECB)
    print 'the decrypted text is: ', des.decrypt(cipher_text)
Run Code Online (Sandbox Code Playgroud)

输出是:

plain Text:  asdfghij

the cipher text is  @?Z????

the decrypted text is:  asdfghij
Run Code Online (Sandbox Code Playgroud)

我的工作有什么不对吗?我也用pyDes得到了相同的结果.

python cryptography des encryption-symmetric pycrypto

7
推荐指数
1
解决办法
1378
查看次数

有什么更好的方法来显示使用 C++ STL 创建的堆栈而不弹出每个元素

我正在尝试使用STL堆栈来解决我希望显示堆栈元素的问题。但我没有找到任何有效的方法来显示而不弹出每个元素。

c++ stl c++11

2
推荐指数
1
解决办法
771
查看次数

具有基类属性是否有效,即使在完成向下转换时它是虚拟的

请参考以下代码:

#define mPtr (static_cast<Dog*> (new(Animal)))

class Animal{
    public:
    virtual void talk(){cout<<"A";}
};
class Dog:public Animal{
    int test;
    public:
    void talk(){bark();}
    void bark(){
        test=0;cout<<test;
    }
};

int main() {

    mPtr->talk();
    mPtr->bark();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

A0
Run Code Online (Sandbox Code Playgroud)

基类talk()正在执行是有效还是未定义的行为?

c++ oop c++11

0
推荐指数
1
解决办法
55
查看次数

标签 统计

c++ ×2

c++11 ×2

cryptography ×1

des ×1

encryption-symmetric ×1

oop ×1

pycrypto ×1

python ×1

stl ×1