⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 des.cpp

📁 用于DES加密以及解密算法的C++代码以及一个控制台实现示例。
💻 CPP
字号:
#include<iostream.h>
#include"des.h"   //DES算法所需的数据表和函数
void main()
{
	static int nCodeLength=30;
	static int nBinaryLength=8*nCodeLength;
    bool *MBits = new bool[nBinaryLength];
	bool *KBits = new bool[nBinaryLength];
	bool *CBits = new bool[nBinaryLength];
// 	char Message[8], Cipher[8];
// 	char Key[8];
	char* Message=new char[nCodeLength];
	char* Cipher=new char[nCodeLength];
	char* Key=new char[nCodeLength];
	char* Message2=new char[nCodeLength];
	cout<<"请输入明文:";
	cin>>Message;
	cout<<"请输入密钥:";
	cin>>Key;
	char* lp;
	lp=Message;
	ByteToBit(Message, MBits, nBinaryLength);
	cout<<"明文二进制为:";
	for(int b = 0; b < nBinaryLength; b++)
		cout<<MBits[b];
	cout<<endl;
	ByteToBit(Key, KBits, nBinaryLength);
	cout<<"Key:"<<endl;
	for(b=0;b<nBinaryLength;b++)
		cout<<KBits[b];
	cout<<endl;
	/////////////////////////////////////////
	cout<<"DES加密:"<<endl;
    DES_Encryption(MBits, KBits, CBits);
	cout<<"密文二进制为:";
	for(b = 0; b < nBinaryLength; b++)
		cout<<CBits[b];
	cout<<endl;
    BitToByte(CBits, Cipher, nBinaryLength);
	cout<<"密文为:";
	for(int i = 0; i < nCodeLength; i++)
	   cout<<Cipher[i];
	cout<<endl;
	/////////////////////////////////////////
	cout<<"DES解密:"<<endl;
	DES_Decryption(CBits, KBits, MBits);
	BitToByte(MBits, Message2, nBinaryLength);
    cout<<"明文为:";
	for(i = 0; i < nCodeLength; i++)
	   cout<<Message2[i];
	cout<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -