Advertisement
onexiv

Untitled

Jan 23rd, 2023 (edited)
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. #include <vector>
  2. #include <fstream>
  3. #include <string>
  4. #include <bitset>
  5. #include <math.h>
  6. #include <iostream>
  7. #include <ctype.h>
  8. #include <sstream>
  9. using namespace std;
  10.  
  11. void collect(ifstream& in, ofstream& out) {
  12.  
  13.     stringstream rd;
  14.     rd << in.rdbuf();
  15.     in.close();
  16.     string buf = rd.str();
  17.     rd.str("");
  18.     // long long unsigned int p = 0;
  19.     string bin = "", p = "";
  20.     for ( ; 0 < buf.length() ; ) {
  21.         // read in 800000 bytes a time. Easily divisible by 8.
  22.         string bf = (buf.length() > 800000) ? buf.substr(0,800000) : buf;
  23.         while (bf.length() > 0)
  24.         {
  25.             // divide bf into 8 character sequences
  26.             string b = (bf.length() >= 8) ? bf.substr(0,8) : (bf.length() > 0) ? buf : "";
  27.            
  28.             // create string of binary from 'b' => 'p'
  29.             for (uint8_t x : b)
  30.                 p += bitset<8>(x).to_string();//(p << 8) + x;
  31.             // This just seems to be the best start to the phi we're using
  32.             // to run up the 'p' binary string
  33.             int i = 3, j = 5, q = 0;
  34.             uint64_t ch = 0;
  35.             while (p.length() > 0)
  36.             {
  37.                 // create 'ch' as 64 bit number, summing as the result of
  38.                 // 3, 5, 8, 13, ... etc numbers of bits. This is constrictive
  39.                 // like a nautilus, which is where i got the idea.
  40.                 ch = bitset<64>(bitset<64>(p).to_string().substr(0,i%64%(p.length() + 1))).to_ullong();
  41.                 while (ch > 0)
  42.                 {
  43.                     bin += (char)ch;
  44.                     ch >>= 8;
  45.                 }
  46.                
  47.                 p = p.substr(i%(p.length()+1));
  48.                 i += j;
  49.                 j += i;
  50.             }
  51.             // get last of characters
  52.             while (ch > 0)
  53.             {
  54.                 bin += (char)ch;
  55.                 ch >>= 8;
  56.             }
  57.             // shorten bf
  58.             bf = (bf.length() > 8) ? bf.substr(8) : "";
  59.         }
  60.         cout << "[" << buf.length() << " " << bin.length() << "]\t\t\r" << flush;
  61.         buf = (buf.length() > 800000) ? buf.substr(800000) : "";
  62.     }
  63.    
  64.     out << bin;
  65.    
  66.     return;
  67. }
  68.  
  69. int main(int argc, char *argv[]) {
  70.     const short MAX_BITS = 8;
  71.  
  72.     string fname = "";
  73.  
  74.         printf("Press, Copyright Aunk 2016 \nInput File: ");
  75.     cin >> fname;
  76.  
  77.     if (fname=="") {
  78.         printf("You must choose a filename to continue...");
  79.         exit(1);
  80.     }
  81.  
  82.     ifstream in {fname.c_str(), std::ios_base::in | std::ios_base::binary};
  83.     if (! in) {
  84.         cout << "I/O Error";
  85.         exit(1);
  86.     }
  87.  
  88.     printf("\nOutput File: ");
  89.     cin >> fname;
  90.  
  91.     if (fname=="") {
  92.         printf("You must choose a filename to continue...");
  93.         exit(1);
  94.     }
  95.  
  96.     ofstream out {fname.c_str(), std::ios_base::out | std::ios_base::trunc };
  97.     if (! out) {
  98.         cout << "I/O Error";
  99.         exit(1);
  100.     }
  101.  
  102.     if (string(argv[1]) == "-c") {
  103.         cout << "Data sorting.. \r\n" << flush;
  104.  
  105.         collect(in,out);
  106.  
  107.         cout << "Complete.\n\nWriting Data.. \n\r[" << flush;
  108.  
  109.         cout << "Complete.\n\nFinal Compression.. Complete." << flush;
  110.  
  111.     }
  112.  
  113.     return 0;
  114.  
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement