home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Security / Security.zip / bfish163.zip / SAMPLE.C < prev    next >
C/C++ Source or Header  |  1998-01-08  |  1KB  |  41 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // SAMPLE.C - Example of Blowfish API call.
  4. //
  5. // Compile this, and link with ENCRYPT.LIB to use encryption functions in DLL
  6. // (or link with ENCRYPT.OBJ to build stand-alone .EXE).
  7. //
  8. // Matthew Spencer, 18/8/95
  9. // Updated 06/01/98, for version 1.62
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <stdio.h>    // for printf()
  13. #include <string.h>   // for strlen()
  14. #include "encrypt.h"
  15.  
  16. int main(int argc, char * argv[])
  17. {
  18.    unsigned char text[] = "This is the sample text to encrypt";   
  19.    unsigned char key[]  = "A sample key.";
  20.    int len = strlen(text);
  21.  
  22.    // version 1.62: setup Chaining mode
  23.    SetChainingMode(ReInitialise);        
  24.  
  25.    // intialise
  26.    Initialise(key, strlen(key));
  27.  
  28.    // display original text
  29.    printf("\nThe original text (%d bytes) is: >>%s<<\n\n", len, text);
  30.  
  31.    // call encryption
  32.    EncryptBlock(text, len);          
  33.    printf("After encryption, the text is:   >>%s<<\n\n", text);
  34.  
  35.    // call decryption - should be the same as the original
  36.    DecryptBlock(text, len);
  37.    printf("After decryption, the text is:   >>%s<<\n\n", text);
  38.  
  39.    return 0;
  40. }
  41.