欢迎来到天天文库
浏览记录
ID:39270574
大小:31.72 KB
页数:12页
时间:2019-06-29
《DES加密算法C语言实验报告》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Word格式DES实验报告一、实验目的实现DES算法。二、实验过程按照DES的算法流程设计,具体实施详见附件。三、使用方法首先输入密钥,八位ASCII长,否则报错。然后输入读入文件名和写入文件名,必须以ASCII编码,否则不能使用。四、实验结果将自身cpp文件进行加密解密,前后文件完全一样。见文件附录源代码://滴一欸死.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include#include#include#include#include#include"ta
2、ble.h"/*Constant*/#defineENCRYPT_LENGTH8//lengthofeachunitinencryption#defineDECIPHER_LENGTH4//lengthofeachunitindecipher#defineMAX320xFFFFFFFF//maskof32bits/*Declaration*/typedefunsignedlonglongbit64;typedefunsignedlonglongbit56;typedefunsignedlonglongbit48;typedefunsignedintbit32;typedefunsignedi
3、ntbit28;/*Filestream*/FILE*fin,*fout;/*Fordebug*/inlinevoidprintBite(bit64num){while(num){完美整理Word格式printf("%d",num%2);num>>=1;}printf("");}/*TransferfromchartobitinEncrtption*/inlinebit64ToBit(char*in//sourcestring);/*TransferfromchartobitinDeciphtering*/inlinebit64DeToBit(char*in//sourcestring)
4、;/*Transferfrombittochar*/inlinevoidToBite(char*out,//outstringbit64num//sourcebits);/*Permutation*/inlinebit64substitute(bit64num,//sourcebitsconstint*table,//Permutationtablesize_tlen//bitslength);/*Bitrecyclelooptoleft*/inlinebit28MoveLeft(bit28key,//sourcebitsintlen//bitslength);/*Bitrecycleloo
5、ptoright*/inlinebit28MoveRight(bit28key,//sourcebitsintlen//bitslength);/*Dividebitsintotwoparts*/inlinevoiddivide(bit64num,//sourcebits完美整理Word格式intlen,//lengthofeachbitsbit32*L,//leftoutbitsbit32*R//rightoutbits);/*Sbox*/inlinebit32SChange(bit48num//sourcebits);/*Fbox*/inlinebit32FChange(bit32num
6、,//sourcebitsbit48key//secretkey);/*Keyinitialization*/inlinevoidSetKey(char*in//stringofkey);/*Enryption*/inlinevoidDES(char*message//messagestobeencrypted);/*Deciphering*/inlinevoidDecipher(char*message//messagestobedeciphered);/*Initialization*/inlinevoidinit();intmain(){init();system("pause");r
7、eturn0;}/*Initialization*/inlinevoidinit(){完美整理Word格式/*Setsecretkey*/printf("Pleaseinputyoursecretkey(8digits):");charkey[10000];scanf("%s",key);if(strlen(key)!=8){printf("ERRORKey");return;}SetKey(key)
此文档下载收益归作者所有