資源簡介
DES加結密算法,明文和密文從文件輸入,明文可以是任意長字符串。加密后的密文放在文件中。

代碼片段和文件信息
#include“feng.h“
#include
#include
///////////////////////////////
??????int?S1[4][16]={
?1441312151183106125907
?0157414213110612119538
?4114813621115129731050
?1512824917511314100613
??};
int?S2[4][16]={
1518146113497213120510
3134715281412011069115
0147111041315812693215
1381013154211671205149
};
int?S3[4][16]={
1009146315511312711428
1370934610285141211151
1364981530111212510147
1101306987415143115212
};
int?S4[4][16]={
7131430691012851112415
1381156150347212110149
1069012117131513145284
3150610113894511127214
};
int?S5[4][16]={
2124171011685315130149
1411212471315015103986
4211110137815912563014
1181271142136150910453
};
int?S6[4][16]=
{
1211015926801334147511
1015427129561131401138
9141552812370410113116
4321295151011141760813
};
int?S7[4][16]=
{
4112141508133129751061
1301174911014351221586
1411131237141015680592
6111381410795015142312
};
int?S8[4][16]={
1328461511110931450127
1151381037412561101492
7114191214206101315358
2114741081315129035611
};
////////////////////////////////
FengHe::FengHe()
{
for(?int?i=0;i<65;i++)
{
binary64[i]=0;
m_IP[i]=0;
}
?for(i=0;i<33;++i)
?{
?Lbinary[i]=0;
?Rbinary[i]=0;
?}
??
}
void?FengHe::GetFileContext(ifstream?&inconst?string?&file)
{
char??s[100];
char?str[9];
//最后一個是放‘\0’表示結束
memset(str9‘\0‘);
memset(s100‘\0‘);
//file.c_str()將string類型轉換為char型字符串
in.open(file.c_str()ios::in|ios::out);
//判斷文件是否打開
if(!in)
cout<<“文件沒有打開?!“< //判斷是否到了文件尾
while(!in.eof())
{
//得到文件的一行然后對這一行進行處理
in.getline(s100);
//得到輸入字符的個數
int?n=strlen(s);
if(n!=0)
{
int?i=-1;
s[n]=‘\0‘;
/////////////////////////////////
for(int?j=0;s[j]!=‘\0‘;++j)
{
//將字符每八個分成一組
++i;
str[i]=s[j];
//得到八個字符時就開始編碼
if(i==7)
{
str[i+1]=‘\0‘;
Char_to_binary64(str9binary6465)?;
Binary_to_Char(binary6465false);
First_Chang_IP(m_IP?65);
DivideSecretKey28(m_SecretKeyReverse1_5657);
Make_IP_intoLR32(m_IP?65);
for(int?m=0;m<16;++m)
{
SecretCircleMove(LsecretKey2829m+1);
SecretCircleMove(RsecretKey2829m+1);
SecretReduceRever2(m_SecretReduce49);
????ExtendRbinary(Rbinary?33);
????XOR(m_Extendbinary49?m_SecretReduce49?m_XOR4849?);
????S_Change(m_XOR4849);
????P_Reverse();
????XOR(m_LastReverse33?Lbinary33?m_XOR3233?);
????ExchangeLR();
}
????ExchangeLR32();
????ReverseIP(m_IP?65);
WriteToFile();
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????10??2010-04-23?23:17??DES\1.txt
?????文件??????????8??2010-04-23?22:47??DES\2.txt
?????文件????????260??2010-04-23?23:58??DES\4.text
?????文件?????585765??2010-04-23?23:58??DES\Debug\DES.exe
?????文件?????333686??2010-04-23?23:58??DES\Debug\he.obj
?????文件???????4475??2010-04-23?23:38??DES\DES.dsp
?????文件????????512??2010-04-03?20:54??DES\DES.dsw
?????文件??????50176??2010-04-23?23:58??DES\DES.ncb
?????文件??????49664??2010-04-23?23:58??DES\DES.opt
?????文件????????240??2010-04-23?23:58??DES\DES.plg
?????文件???????1538??2010-04-23?22:56??DES\feng.h
?????文件??????14628??2010-04-23?23:37??DES\he.cpp
?????目錄??????????0??2010-04-23?23:58??DES\Debug
?????目錄??????????0??2010-04-23?23:58??DES
-----------?---------??----------?-----??----
??????????????1040962????????????????????14
- 上一篇:handlebars官方及源代碼
- 下一篇:試設計一個用回溯法搜索排列空間樹的函數
評論
共有 條評論