计算程序执行10万次需要的时间:
总共需要175秒
加解密一次的时间小于:0.00175秒
纯计算加解密的时间会更短
去除IO操作后的时间
也就是说加解密一次的时间为0.07毫秒
1 /*------------------------------------------------------- 2 Data Encryption Standard 56位密钥加密64位数据 3 --------------------------------------------------------*/ 4 #include <stdlib.h> 5 #include <stdio.h> 6 #include <time.h> 7 #include "bool.h" // 位处理 8 #include "tables.h" 9 10 void BitsCopy(bool *DatOut, bool *DatIn, int Len); // 数组复制 11 12 void ByteToBit(bool *DatOut, char *DatIn, int Num); // 字节到位 13 void BitToByte(char *DatOut, bool *DatIn, int Num); // 位到字节 14 15 void BitToHex(char *DatOut, bool *DatIn, int Num); // 二进制到十六进制 64位 to 4*16字符 16 void HexToBit(bool *DatOut, char *DatIn, int Num); // 十六进制到二进制 17 18 void TablePermute(bool *DatOut, bool *DatIn, const char *Table, int Num); // 位表置换函数 19 void LoopMove(bool *DatIn, int Len, int Num); // 循环左移 Len长度 Num移动位数 20 void Xor(bool *DatA, bool *DatB, int Num); // 异或函数 21 22 void S_Change(bool DatOut[32], bool DatIn[48]); // S盒变换 23 void F_Change(bool DatIn[32], bool DatKi[48]); // F函数 24 25 void SetKey(char KeyIn[8]); // 设置密钥 26 void PlayDes(char MesOut[8], char MesIn[8]); // 执行DES加密 27 void KickDes(char MesOut[8], char MesIn[8]); // 执行DES解密 28 29 30 31 int main() 32 { 33 clock_t aaa, bbb; 34 int jjj = 0; 35 aaa = time(NULL); 36 while (jjj <100000) 37 { 38 int i = 0; 39 char MesHex[16] = { 0 }; // 16个字符数组用于存放 64位16进制的密文 40 char MyKey[8] = { 0 }; // 初始密钥 8字节*8 41 char YourKey[8] = { 0 }; // 输入的解密密钥 8字节*8 42 char MyMessage[8] = { 0 }; // 初始明文 43 44 /*-----------------------------------------------*/ 45 46 printf("Welcome! Please input your Message(64 bit): "); 47 //gets(MyMessage); // 明文 48 MyMessage[0] = '1'; 49 MyMessage[1] = '2'; 50 MyMessage[2] = '3'; 51 MyMessage[3] = '4'; 52 MyMessage[4] = '5'; 53 MyMessage[5] = '6'; 54 MyMessage[6] = '7'; 55 MyMessage[7] = '8'; 56 //MyMessage[0] = ' '; 57 printf("Please input your Secret Key: "); 58 MyKey[0] = '1'; // 密钥 59 MyKey[1] = '2'; 60 MyKey[2] = '3'; 61 MyKey[3] = '4'; 62 MyKey[4] = '5'; 63 MyKey[5] = '6'; 64 MyKey[6] = '7'; 65 MyKey[7] = '8'; 66 //MyKey[8] = ' '; 67 while (MyKey[i] != '