Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <fstream>
- #include <string>
- #include <bitset>
- #include <math.h>
- #include <iostream>
- #include <ctype.h>
- #include <sstream>
- using namespace std;
- void collect(ifstream& in, ofstream& out) {
- stringstream rd;
- rd << in.rdbuf();
- in.close();
- string buf = rd.str();
- rd.str("");
- // long long unsigned int p = 0;
- string bin = "", p = "";
- for ( ; 0 < buf.length() ; ) {
- // read in 800000 bytes a time. Easily divisible by 8.
- string bf = (buf.length() > 800000) ? buf.substr(0,800000) : buf;
- while (bf.length() > 0)
- {
- // divide bf into 8 character sequences
- string b = (bf.length() >= 8) ? bf.substr(0,8) : (bf.length() > 0) ? buf : "";
- // create string of binary from 'b' => 'p'
- for (uint8_t x : b)
- p += bitset<8>(x).to_string();//(p << 8) + x;
- // This just seems to be the best start to the phi we're using
- // to run up the 'p' binary string
- int i = 3, j = 5, q = 0;
- uint64_t ch = 0;
- while (p.length() > 0)
- {
- // create 'ch' as 64 bit number, summing as the result of
- // 3, 5, 8, 13, ... etc numbers of bits. This is constrictive
- // like a nautilus, which is where i got the idea.
- ch = bitset<64>(bitset<64>(p).to_string().substr(0,i%64%(p.length() + 1))).to_ullong();
- while (ch > 0)
- {
- bin += (char)ch;
- ch >>= 8;
- }
- p = p.substr(i%(p.length()+1));
- i += j;
- j += i;
- }
- // get last of characters
- while (ch > 0)
- {
- bin += (char)ch;
- ch >>= 8;
- }
- // shorten bf
- bf = (bf.length() > 8) ? bf.substr(8) : "";
- }
- cout << "[" << buf.length() << " " << bin.length() << "]\t\t\r" << flush;
- buf = (buf.length() > 800000) ? buf.substr(800000) : "";
- }
- out << bin;
- return;
- }
- int main(int argc, char *argv[]) {
- const short MAX_BITS = 8;
- string fname = "";
- printf("Press, Copyright Aunk 2016 \nInput File: ");
- cin >> fname;
- if (fname=="") {
- printf("You must choose a filename to continue...");
- exit(1);
- }
- ifstream in {fname.c_str(), std::ios_base::in | std::ios_base::binary};
- if (! in) {
- cout << "I/O Error";
- exit(1);
- }
- printf("\nOutput File: ");
- cin >> fname;
- if (fname=="") {
- printf("You must choose a filename to continue...");
- exit(1);
- }
- ofstream out {fname.c_str(), std::ios_base::out | std::ios_base::trunc };
- if (! out) {
- cout << "I/O Error";
- exit(1);
- }
- if (string(argv[1]) == "-c") {
- cout << "Data sorting.. \r\n" << flush;
- collect(in,out);
- cout << "Complete.\n\nWriting Data.. \n\r[" << flush;
- cout << "Complete.\n\nFinal Compression.. Complete." << flush;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement