/*-------------------------------------------------------
Data Encryption Standard 56位密钥加密64位数据
2016.10
--------------------------------------------------------*/
#include
#include
#include "bool.h" // 位处理
#include "tables.h"
void BitsCopy(bool *DatOut,bool *DatIn,int Len); // 数组复制
void ByteToBit(bool *DatOut,char *DatIn,int Num); // 字节到位
void BitToByte(char *DatOut,bool *DatIn,int Num); // 位到字节
void BitToHex(char *DatOut,bool *DatIn,int Num); // 二进制到十六进制 64位 to 4*16字符
void HexToBit(bool *DatOut,char *DatIn,int Num); // 十六进制到二进制
void TablePermute(bool *DatOut,bool *DatIn,const char *Table,int Num); // 位表置换函数
void LoopMove(bool *DatIn,int Len,int Num); // 循环左移 Len长度 Num移动位数
void Xor(bool *DatA,bool *DatB,int Num); // 异或函数
void S_Change(bool DatOut[32],bool DatIn[48]); // S盒变换
void F_Change(bool DatIn[32],bool DatKi[48]); // F函数
void SetKey(char KeyIn[8]); // 设置密钥
void PlayDes(char MesOut[8],char MesIn[8]); // 执行DES加密
void KickDes(char MesOut[8],char MesIn[8]); // 执行DES解密
int main()
{
int i=0;
char MesHex[16]={0}; // 16个字符数组用于存放 64位16进制的密文
char MyKey[8]={0}; // 初始密钥 8字节*8
char YourKey[8]={0}; // 输入的解密密钥 8字节*8
char MyMessage[8]={0}; // 初始明文
/*-----------------------------------------------*/
printf("Welcome! Please input your Message(64 bit):\n");
gets(MyMessage); // 明文
printf("Please input your Secret Key:\n");
gets(MyKey); // 密钥
while(MyKey[i]!='\0') // 计算密钥长度
{
i++;
}
while(i!=8) // 不是8 提示错误
{
printf("Please input a correct Secret K