📄 unit1.cpp
字号:
else if(RadioButton2->Checked==true)
{
BOOL c_tmp[64];
BYTE byte_ptext;
BOOL bool_ptext;
BOOL bool_crytext[8];
BYTE byte_crytext;
str1="";
for(i=0;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
s[i]=s[i]-48;
else if(s[i]>='a'&&s[i]<='z')
s[i]=s[i]-87;
else if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]-55;
}
plaintext=(BYTE *)malloc(len2);
memset(plaintext,0,len2);
all_len=len2;
for(i=0;i<len/2;i++)
{
plaintext[i]=s[2*i]*16+s[2*i+1];
}
if(len%2==1)
plaintext[i]=s[2*i]*16;
for(i=0;i<8*len2;i++)
{
for(k=0;k<64;k++)
c_tmp[k]=iv[k];
en_decrypt(c_tmp,key,'e');
byte_ptext=plaintext[i/8];
bool_ptext=(byte_ptext>>(7-i%8))&1;
for(k=0;k<63;k++)
iv[k]=iv[k+1];
iv[63]=bool_ptext;
bool_ptext=bool_ptext^c_tmp[0];
bool_crytext[i%8]=bool_ptext;
if(i%8==7)
{
btbyte(&byte_crytext,bool_crytext,8);
str1.cat_printf("%2.2x",byte_crytext);
}
}
free(plaintext);
}
else if(RadioButton3->Checked==true)
{
BOOL c_bool[8];
BYTE c_print;
BOOL c_tmp[64];
str2="";
for(i=0;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
s[i]=s[i]-48;
else if(s[i]>='a'&&s[i]<='z')
s[i]=s[i]-87;
else if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]-55;
}
plaintext=(BYTE *)malloc(len2);
memset(plaintext,0,len2);
all_len=len2;
for(i=0;i<len/2;i++)
{
plaintext[i]=s[2*i]*16+s[2*i+1];
}
if(len%2==1)
plaintext[i]=s[2*i]*16;
for(i=0;i<len2;i++)
{
for(k=0;k<64;k++)
c_tmp[k]=iv[k];
en_decrypt(c_tmp,key,'e');
btbit(c_bool,&plaintext[i],8);
xor(c_tmp,c_bool,8);
btbyte(&c_print,c_tmp,8);
for(k=0;k<64-8;k++)
iv[k]=iv[k+8];
for(k=0;k<8;k++)
iv[64-8+k]=c_bool[k];
str1.cat_printf("%2.2x",c_print);
}
free(plaintext);
}
else if(RadioButton4->Checked==true)
{
BOOL c_bool[64];
BYTE c_print[8];
BOOL c_tmp[64];
str1="";
for(i=0;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
s[i]=s[i]-48;
else if(s[i]>='a'&&s[i]<='z')
s[i]=s[i]-87;
else if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]-55;
}
plaintext=(BYTE *)malloc(len2);
memset(plaintext,0,len2);
all_len=len2;
for(i=0;i<len/2;i++)
{
plaintext[i]=s[2*i]*16+s[2*i+1];
}
if(len%2==1)
plaintext[i]=s[2*i]*16;
for(i=0;i<(len2-1)/8+1;i++)
{
for(k=0;k<64;k++)
c_tmp[k]=iv[k];
en_decrypt(c_tmp,key,'e');
btbit(c_bool,&plaintext[8*i],8*((len2-8*i)<8?(len2-8*i):8));
xor(c_tmp,c_bool,64);
btbyte(c_print,c_tmp,64);
for(k=0;k<64;k++)
iv[k]=c_bool[k];
if(len2-8*i<8)
{
for(k=0;k<len2-8*i;k++)
str1.cat_printf("%2.2x",c_print[k]);
}
else
{
for(k=0;k<8;k++)
str1.cat_printf("%2.2x",c_print[k]);
}
}
free(plaintext);
}
Memo1->Lines->Text=str1;
free(s);
end=GetTickCount();
effic=(end-start)*1.0/1000/all_len;
String tmp="运行速度:";
tmp+=FloatToStrF(effic,ffFixed,0,7);
tmp+="sec/byte!";
MessageBox(Handle,tmp.c_str(),"提示:",MB_OK|MB_ICONEXCLAMATION);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Memo1KeyPress(TObject *Sender, char &Key)
{
if('0'<=Key&&Key<='9'|| 'a'<=Key&&Key<='f'|| 'A'<=Key&&Key<='F'||Key==VK_TAB||Key==VK_DELETE||Key==VK_BACK)
return;
else
Key=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if('0'<=Key&&Key<='9'|| 'a'<=Key&&Key<='f'|| 'A'<=Key&&Key<='F'||Key==VK_TAB||Key==VK_DELETE||Key==VK_BACK)
return;
else
Key=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key)
{
if('0'<=Key&&Key<='9'|| 'a'<=Key&&Key<='f'|| 'A'<=Key&&Key<='F'||Key==VK_TAB||Key==VK_DELETE||Key==VK_BACK)
return;
else
Key=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Directry1Click(TObject *Sender)
{
if(OpenDialog1->Execute())
{
fileopen=OpenDialog1->FileName;
String tmp=fileopen; //显示源文件名
int pos;
while((pos=tmp.Pos("\\"))!=0)
{
tmp.Delete(1,pos);
}
Label7->Caption=tmp;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Directry2Click(TObject *Sender)
{
if(fileopen=="")
{
MessageBox(Handle,"请先设置源文件!","提示",MB_OK|MB_ICONEXCLAMATION);
return;
}
SaveDialog1->FileName=fileopen;
if(SaveDialog1->Execute())
{
filesave=SaveDialog1->FileName;
String tmp=fileopen; //判断后缀并显示目标文件名
int pos;
while((pos=tmp.Pos("\\"))!=0)
{
tmp.Delete(1,pos);
}
pos=tmp.Pos('.');
tmp.Delete(1,pos-1);
if(filesave.SubString(filesave.Length()-tmp.Length()+1,tmp.Length())!=fileopen.SubString(fileopen.Length()-tmp.Length()+1,tmp.Length()))
filesave+=tmp;
tmp=filesave;
while((pos=tmp.Pos("\\"))!=0)
{
tmp.Delete(1,pos);
}
Label9->Caption=tmp;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Encrypt2Click(TObject *Sender)
{
if(fileopen=="")
{
MessageBox(Handle,"请先设置源文件!","提示",MB_OK|MB_ICONEXCLAMATION);
return;
}
if(filesave=="")
{
MessageBox(Handle,"请先设置目标文件!","提示",MB_OK|MB_ICONEXCLAMATION);
return;
}
DWORD len,len2,i,j,k,pi;
BYTE crypt[8];
DWORD start,end;
DWORD all_len=0;
double effic;
start=GetTickCount();
BOOL key[64];
BOOL iv[64];
iv_keychange(key,iv,Edit3->Text.c_str(),Edit4->Text.c_str());
FILE *fSourse,*fDestination;
fSourse=fopen(fileopen.c_str(),"rb");
fDestination=fopen(filesave.c_str(),"wb");
if(RadioButton5->Checked==true)
{
BOOL text[64]; //CBC模式
BYTE plaintext[64];
DWORD dwCount;
Screen->Cursor=crHourGlass; //从文件中一次读取64字节处理
while(feof(fSourse)==0)
{
dwCount=fread(plaintext,1,64,fSourse);
if(dwCount==0)
break;
all_len+=dwCount;
for(i=0;i<dwCount/8;i++)
{
btbit(text,&plaintext[8*i],64);
xor(iv,text,64);
en_decrypt(iv,key,'e');
btbyte(crypt,iv,64);
for(k=0;k<8;k++)
plaintext[8*i+k]=crypt[k];
}
if(dwCount%8!=0)
{
for(k=dwCount%8;k<7;k++)
plaintext[8*i+k]=0;
plaintext[8*i+7]=8-dwCount;
btbit(text,&plaintext[8*i],64);
xor(iv,text,64);
en_decrypt(iv,key,'e');
btbyte(crypt,iv,64);
for(k=0;k<8;k++)
plaintext[8*i+k]=crypt[k];
}
fwrite(plaintext,1,(dwCount%8==0)?dwCount:dwCount+8-dwCount%8,fDestination);
}
Screen->Cursor=crDefault;
}
else if(RadioButton6->Checked==true)
{
BOOL c_tmp[64];
BYTE byte_ptext;
BOOL bool_ptext; //CFB-1模式
BOOL bool_crytext[8];
BYTE byte_crytext;
DWORD dwCount;
BYTE plaintext[64];
while(feof(fSourse)==0)
{
dwCount=fread(plaintext,1,64,fSourse);
if(dwCount==0)
break;
all_len+=dwCount;
for(i=0;i<dwCount;i++)
{
for(j=0;j<8;j++)
{
for(k=0;k<64;k++)
c_tmp[k]=iv[k];
en_decrypt(c_tmp,key,'e');
byte_ptext=plaintext[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -