XOR Encryptor


Almost all programmers must be aware of this encryption algorithm. Needless to say, this algorithm can easily be broken into. Nevertheless,  I have tried to bring out a graphical version of the same using a two-tier architecture of VB and VC++.

The front-end  has been designed using VB 6.0 which basically contains a couple of text boxes and buttons.

The back-end has been designed using VC++ (ATL COM) and the code can be built into a .dll file.

A detailed procedure of the working is given here - 

  • A source file to be encrypted is selected using the Open Dialog.

  • A destination file name is given. (This will be the encrypted file).

  • A suitable password is given.

  • VB then passes this information to en2.dll file which then encrypts the contents of the file using the XOR algorithm.

  • The source file is then deleted.

  • To get back the original file, follow the same steps.  (Remember, the password should be accurate).

To begin with, create a new ATL COM wizard project in VC++. Follow the instructions of the wizard and do not ever forget to check on Support MFC check box. Click on Insert - New ATL object  - Simple Object - and then give a suitable name. Go to class view, right click on the interface name you just gave and click on add method.

Give the method name as acceptfilepass and parameters as [in] BSTR sid, [in] BSTR did,[in] BSTR passwd

Encryption function  given here  (enpt.cpp)- 

STDMETHODIMP Cenpt::acceptfilepass ( BSTR sid, BSTR did, BSTR passw )
{

AFX_MANAGE_STATE ( AfxGetStaticModuleState( ) )

// TODO: Add your implementation code here
FILE *src,*dest ;
CString strobj1 ( sid ) ;                  //Create an object of CString from BSTR
CString strobj2 ( did ) ;
CString strobj3 ( passw ) ;          
char p[20] ;
strcpy ( p, strobj3 ) ;
char ch1 ;
char *ptr1 ;

src = fopen ( strobj1, "rb" ) ;
dest = fopen ( strobj2, "wb" ) ;

ptr1 = p ;
for( *--ptr1 = 0 ; fread ( &ch1, sizeof ( ch1 ), 1, src ) == 1 ; )
{

ch1 ^= *( *ptr1 ? ptr1++ : ( ptr1 = p ) ) ;             //Perform XOR Operation here.
fwrite ( &ch1, sizeof ( ch1 ), 1, dest ) ;

}

 

fclose ( src ) ;
fclose ( dest ) ;
return S_OK ;

}

The function is pretty simple and involves usual file operations of C. Add a reference to the project in VB and then design the controls and the project is done. For more info mail me at nshankar@angelfire.com

Download