Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2015
1,858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <windows.h> // Sleep
  6.  
  7. bool is_encrypted(const char *s, unsigned long seed)
  8. {
  9.      srand(seed);
  10.  
  11.      size_t len = strlen(s);
  12.      unsigned int i; for(i = 0; i < len; ++i)
  13.      {
  14.          if( (rand() % 27 + 'a') != s[i] )
  15.             return false;
  16.      }
  17.      return rand() % 27 == 26; //26 is the new \0
  18. }
  19.  
  20. int main()
  21. {
  22.     const char *data = "ayyyy";
  23.     unsigned long seed = -1;
  24.  
  25.     clock_t before = clock();
  26.     do
  27.     {
  28.         if ( ++seed == (unsigned long)(-1) ) exit(1);
  29.     }
  30.     while( !is_encrypted(data, seed) );
  31.     clock_t after = clock();
  32.     double seconds_took = (double)(after - before) / CLOCKS_PER_SEC;
  33.  
  34.     system("color 0a");
  35.     printf("Encryption took only %.2fs!\n", seconds_took);
  36.     printf("Here's your TOP SECRET KEY: %lu\n", seed);
  37.     printf("Decrypting");
  38.     putchar('.'); Sleep(500);
  39.     putchar('.'); Sleep(500);
  40.     putchar('.'); Sleep(500);
  41.     putchar('\n');
  42.  
  43.     srand(seed);
  44.     char c, *ptr, decrypted[256]; //Does it need to be bigger?  ¯\_(ツ)_/¯
  45.     ptr = &decrypted[0];
  46.  
  47.     while( (c = rand() % 27 + 'a') != ('z' + 1) ) *ptr++ = c;
  48.     *ptr = '\0';
  49.  
  50.     printf("Decrypted text: %s", decrypted);
  51.     getchar();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement