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

  1. #include  <string.h>
  2. #include  <stdlib.h>
  3. #include  <stdio.h>
  4. #include <iomanip.h>
  5. #include "cactus.hpp"
  6. int main(int argc, char * argv[]){
  7. char * key, * msk;
  8. char *path;
  9. char * seed;
  10. char ch;
  11. unsigned long i,j;
  12. unsigned long seed_len;
  13.  
  14. MiCactus crypt;
  15. if (!registered) cout << "\a >>> Please register RNG.EXE! \a\n";
  16.  
  17. if (argc < 4) {
  18.    cout << "Random Number Generator using the CACTUS-Algorithm" << '\n'
  19.         << "Author: Michael Mieves, Version 1.0, April 1996." << '\n'
  20.         << "RNG writes random numbers into a file." << '\n'
  21.         << "Usage: RNG <filename> <filelength> <preruns> [SEED]" << '\n';
  22.         return 0;
  23.    }
  24. cout << "Please wait . . ." << '\n';
  25. char name[256];
  26. strcpy(name,argv[1]);
  27. key = new char[crypt.lenall];
  28. msk = new char[256];
  29. for (i = 0;i<crypt.lenall;i++){
  30.             key[i] = 0;
  31.             }
  32. for (i = 0;i<256;i++){
  33.             msk[i] = 0;
  34.             }
  35. if(path = getenv("CACTUSKEY")){
  36.       ifstream inkey(path,ios::binary|ios::ate);
  37.       seed_len = inkey.tellg();
  38.       inkey.seekg(0);
  39.       j = 0;
  40.       for (i = 0;i<crypt.lenall;i++){
  41.            inkey >> key[i];
  42.            j++;
  43.            if (j == seed_len) {
  44.               inkey.seekg(0);
  45.               j = 0;
  46.               }
  47.            }
  48.       for (i = 0;i<256;i++){
  49.            if(inkey.eof()) inkey.seekg(0);
  50.            inkey >> msk[i];
  51.            j++;
  52.            if (j == seed_len) {
  53.               inkey.seekg(0);
  54.               j = 0;
  55.               }
  56.            }
  57.       inkey.close();
  58.       }
  59. if (argc == 5){
  60.      seed_len = strlen(argv[4]);
  61.      seed = new char[seed_len];
  62.      strcpy(seed,argv[4]);
  63.      j = 0;
  64.      for (i = 0;i<crypt.lenall;i++){
  65.            key[i] ^= seed[j];
  66.            j++;
  67.            if(j == seed_len) j = 0;
  68.            }
  69.       for (i = 0;i<256;i++){
  70.            msk[i] ^= seed[j];
  71.            j++;
  72.            if(j == seed_len) j = 0;
  73.            }
  74.         }
  75. crypt.initiate(key,msk);
  76. crypt.reset(key,msk,strtoul(argv[3],NULL,10));
  77. ofstream out(name,ios::binary);
  78. for (i=0;i<strtoul(argv[2],NULL,10);i++){
  79.    out << crypt.gen_byte();
  80.    }
  81. out.close();
  82. return 1;
  83. }
  84.