DES的代码,因为是用QT写的。所以说直接复制粘贴是不能运行的啊。

/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of th
摘要由CSDN通过智能技术生成
/*This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
#ifndef DES_H
#define DES_H

#include <QObject>
#define Key unsigned char
#define Data unsigned int
class DES : public QObject
{
    Q_OBJECT
private:
    Key myKey[8];
    Key subkeyList[16][6];
    Data data[2];
    unsigned int f;
public:
    explicit DES(QObject *parent = 0);
    void creatRandomKey();
    void creatSubkey();
    void setKey()
    void setData(Data data0,Data data1){data[0]=data0;data[1]=data1;}
    void IP();
    void IPInv();
    void crypt(int no);
    void swap(){std::swap(data[0],data[1]);}
    template <typename T>
    void printb(T t[],int num,char *str = NULL);


    unsigned char getbit(Key key[],int num){return ((key[num/8]>>(7-num%8)) & 1);}
    void putbit(Key key[],int num,unsigned char bit){key[num/8] |= (bit<<(7-num%8));}
signals:
public slots:
};

#endif // DES_H

#include "des.h"
#include <memory>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstdlib>
DES::DES(QObject *parent) :
    QObject(parent)
{
}
void DES::creatRandomKey(){
    srand(time(NULL));
    for(int i=0;i<8;++i)
        myKey[i] = (rand()%128)<<1;
    //忽略奇偶校验位
    std::cout<<"KEY:";
    for (int i=0;i<8;++i)
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值