?? encrypt.c
字號(hào):
//////////////////////////////////////////////////////////////////////////////
// ************************** //
// *Data Encryption Standard* //
// ************************** //
// //
// Realized in C //
// //
// ************* //
// *Constructed* //
// * By * //
// * * //
// *Xie Xingwei* //
// ************* //
// //
// If you have any question about my code,contact me with E-mail please //
// //
// xiexingwei_2008@hotmail.com //
//////////////////////////////////////////////////////////////////////////////
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#include "key_gen.h"
#include "des.h"
#include "data_struct.h"
int main()
{
int pfh,cfh; /*Handle of the file "plaintext" and "ciphertext"*/
unsigned char Lbuffer[1000];/*Buffer for plaintext storage*/
unsigned char Lresult[1000];/*Buffer for ciphertext storage*/
unsigned char buffer[8];/*Buffer for DES input*/
int i,x;
if(key_gen())
{
perror("Problem in generating subkeys");
}
/* Open file for input: */
if( (pfh = _open( "plaintext", _O_RDONLY )) == -1 )
{
perror( "Can not open the file \"plaintext\" " );
_close( pfh );
return 1;
}
/* Read in input: */
if( ( _read( pfh, Lbuffer, 100 ) ) <= 0 )
{
perror( "Problem reading file" );
_close( pfh );
return 1;
}
/*Create ciphertext file*/
cfh=_creat( "ciphertext", _S_IREAD | _S_IWRITE );
if( cfh == -1 )
{
perror( "Couldn't create ciphertext file" );
_close( cfh );
}
while(Lbuffer[0]!='\0')
{
for(i=0;i<125;i++)
{
for(x=0;x<8;x++)
{
buffer[x]=Lbuffer[i*8+x];
}
if(des(buffer))
{
perror( "Problem encrypting data" );
return 1;
}
for(x=0;x<8;x++)
{
Lresult[i*8+x]=buffer[x];
}
}
/*Write data to ciphertext file*/
if((_write( cfh, Lresult, 1000 ) )==-1)
{
perror( "Failed when wrote data to buffer" );
_close(cfh);
}
/*Make the Lbuffer clean*/
for(i=0;i<1000;i++)
{
Lbuffer[i]='\0';
}
/* Read in input: */
_read( pfh, Lbuffer, 1000 );
}
_close(pfh);
_close(cfh);
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -