资源描述:
《des加密解密纯c语言实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#includevoidshow1()//主界面{printf("tt***************DES加密解密系统******************");printf("tt--------------------------------------------------");//printf("tt--------------------------------------------------");printf
2、("tt**************************************************");printf("tt**tttttt**");printf("tt**tttttt**");printf("tt**ttt1.加密ttt**");printf("tt**tttttt**");printf("tt**ttt2.解密ttt**");printf("tt**tttttt**");printf("tt
3、**ttt3.退出ttt**");printf("tt**tttttt**");printf("tt**tttttt**");printf("tt--------------------------------------------------");}voidshow2()//加密界面{printf("tt******************DES加密**********************");printf("tt--------------------
4、------------------------------");printf("tt**************************************************");printf("tt**tttttt**");printf("tt**t请选择明文和密钥的输入方式:tt**");printf("tt**tttttt**");printf("tt**tt1.直接输入ttt**");printf("tt**tttttt**");
5、printf("tt**tt2.从文件读取ttt**");printf("tt**tttttt**");printf("tt**tt3.退出tttt**");printf("tt**tttttt**");printf("tt--------------------------------------------------");printf("ttt选择:");}voidreader(charstr[30],chars[8])//读取明文和密钥{FILE*fp;
6、fp=fopen(str,"r");if(fp==NULL){printf("明文读取失败!");}else{fscanf(fp,"%s",s);}fclose(fp);}voidTo2Bin(charp[8],intb[64])//将字节转换成二进制流{inti,k=0;for(i=0;i<8;i++){intj=0x80;for(;j;j>>=1){if(j&p[i]){b[k++]=1;}else{b[k++]=0;}}}}intIP_Table[64]=//初始置换(IP){57,49,41,33,25,17,9,1,59,51,43,35
7、,27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,31,23,15,7,56,48,40,32,24,16,8,0,58,50,42,34,26,18,10,2,60,52,44,36,28,20,12,4,62,54,46,38,30,22,14,6};intE_Table[]={//扩展变换E31,0,1,2,3,4,3,4,5,6,7,8,7,8,9,10,11,12,11,12,13,14,15,16,15,16,17,18,19,20,19,20,21,22,23,24,23,24,25,26,27
8、,28,27,28,29,30,31,0};intS_Box[8][4][16]={//8个s