home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cactus.zip / Source / FCryptX.cpp < prev    next >
Text File  |  1996-04-14  |  2KB  |  71 lines

  1. #include  <string.h>
  2. #include  <stdlib.h>
  3. #include  <stdio.h>
  4. #include <iomanip.h>
  5. #include <fstream.h>
  6. #include "cactus.hpp"
  7.  
  8. int main(int argc, char * argv[]){
  9. char clr[256],cry[256];
  10. char * key, * msk;
  11. char *path;
  12. char ch;
  13. unsigned long i,j;
  14. MiCactus crypt;
  15. if (!registered) cout << "\a >>> Please register FCryptX.EXE! \a\n";
  16. if (argc < 4) {
  17.    cout << "File encryption using the CACTUS-Algorithm." << '\n'
  18.         << "Author: Michael Mieves, Version 1.0, April 1996." << '\n'
  19.         << "FCryptX produces an encrypted/decrypted file." << '\n'
  20.         << "Usage: FCryptX -e|d <clearfile> <cryptfile> " << '\n'
  21.         << "-e encrypts an clear file, -d decrypts a crypted file." << '\n';
  22.         return 0;
  23.    }
  24. cout << "Please wait . . ." << '\n';
  25. char mode[3];
  26. int crypt_flag;
  27. strcpy(mode,argv[1]);
  28. strcpy(clr,argv[2]);
  29. strcpy(cry,argv[3]);
  30. key = new char[crypt.lenall];
  31. msk = new char[256];
  32. for (i = 0;i<crypt.lenall;i++){
  33.             key[i] = 0;
  34.             }
  35. for (i = 0;i<256;i++){
  36.             msk[i] = 0;
  37.             }
  38. if(path == getenv("CACTUSKEY")){
  39.       ifstream inkey(path,ios::binary);
  40.       for (i = 0;i<crypt.lenall;i++){
  41.            inkey >> key[i];
  42.            }
  43.       for (i = 0;i<256;i++){
  44.            inkey >> msk[i];
  45.            }
  46.       inkey.close();
  47.       }
  48.  
  49. crypt.initiate(key,msk);
  50.  
  51. if (mode[1] == 'e'){
  52.     crypt.reset(key,msk,0);
  53.     ifstream infile(clr,ios::binary);
  54.     ofstream outfile(cry,ios::binary);
  55.     while(infile.get(ch))outfile.put((char)(ch ^ crypt.gen_byte()));
  56.     infile.close();
  57.     outfile.close();
  58.  
  59. }
  60.  else{
  61.     crypt.reset(key,msk,0);
  62.     ifstream infile(cry,ios::binary);
  63.     ofstream outfile(clr,ios::binary);
  64.     while(infile.get(ch))outfile.put((char)(ch ^ crypt.gen_byte()));
  65.     infile.close();
  66.     outfile.close();
  67.  
  68. }
  69. return 1;
  70. }
  71.