home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / os2 / bfish / SAMPLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-22  |  1.2 KB  |  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 22/7/97
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <stdio.h>    // for printf()
  13. #include <string.h>   // for strlen()
  14. #include "encrypt.h"
  15.  
  16. int main()
  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.    // set version
  23.    SetVersion(161); // new requirement with version 1.61
  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.