Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Kcracken v0.1
- *
- * Thank you to Dr. Dr. Morton,
- * Whom without the help of his
- * once in his classroom, I
- * would not have reviled math
- * as I now do -thexiv
- */
- #include <bitset>
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <iterator>
- #include <algorithm>
- #include <vector>
- #include <math.h>
- using namespace std;
- class S_Rend {
- protected:
- bitset<8> alpha, lambda, delta;
- vector<char> credit;
- vector<int> bean_trace;
- vector<int> lambdas;
- public:
- int length = 0;
- S_Rend() { delta=0x00; lambda=0x00; alpha=0x00; delta=0x00; };
- ~S_Rend() { };
- long uncompress(ifstream&,ofstream&);
- long compress(ifstream&,ofstream&);
- long counter(long t);
- long recover_data_point(long, long, int);
- } n;
- /*+**- Project::Sailwinds -**+*/
- // bean = counter byte = lambda ch = credited char
- long S_Rend::recover_data_point(long bean, long byte, int ch) {
- printf("*");
- if (length - bean == 1)
- return 0;
- if (credit.size() < 1 || bean_trace[bean_trace.size()-1] ^ credit[credit.size()-1] ^ lambdas[lambdas.size()-1] == byte) {
- bean_trace.push_back(bean);
- credit.push_back(ch);
- byte ^= bean ^ ch;
- lambdas.push_back(byte);
- return ch ^ byte;
- }
- else
- exit(0);
- }
- long S_Rend::counter(long t) {
- t+=1;
- return t;
- }
- long S_Rend::compress(ifstream& in, ofstream& out) {
- char last;
- long long t;
- bitset<8> fox = 0;
- if (!(in.is_open()))
- { return -1; }
- else {
- t= 0;
- for_each (std::istreambuf_iterator<char>(in), \
- std::istreambuf_iterator<char>(), \
- [&] (char x) {
- t=counter(t);
- alpha = t;
- delta = x;
- // take delta ^ alpha (recurse ^ chars) from lambda == next lambda
- fox = lambda;
- lambda ^= (delta ^ alpha);
- if (lambda.to_ulong() == 0)
- { out << fox.to_ulong();
- out << " " << t << " " << (char)(last) << endl;
- t = 0;
- }
- last = x;
- });
- printf("*");
- }
- if (out.is_open() && t > 0)
- { out << fox.to_ulong();
- out << " " << t << " " << (char)(last) << endl; }
- else { return -1; }
- in.close();
- out.close();
- return 0;
- }
- long S_Rend::uncompress(ifstream& in, ofstream& out) {
- short int i = 0, j = 0, h = 0, k = 0;
- char ch;
- long t = 0, mrc = 0;
- int y = 0;
- while (in >> t >> y >> ch) {
- length = y;
- printf("%u %u %c | ", y, t, ch);
- mrc = 0;
- int ess = 0, cnt = 1;
- while (ess < length) {
- //recover_data_point(y, t, ch);
- i = j = 0;
- if (ess%2 == 0) {
- i = h = 0;
- while (length > y+i) h ^= (int)i++;
- i = 0;
- while ((i ^ h) != mrc) (int)i++;
- --y;
- }
- else {
- i = 1;
- while (cnt > i) j ^= (int)i++;
- i = 0;
- while ((i ^ j) != mrc) (int)i++;
- ++cnt;
- }
- ess++;
- printf("*");
- credit.push_back((char)i);
- t ^= (int)j;
- t ^= (int)(i);
- ch = i;
- mrc = t;
- }
- i= credit.size();
- while (i >= 0) {
- char temp = credit[--i];
- if (temp > 128)
- out << (char)(abs(temp));
- else
- out << (char)(temp);
- }
- credit.clear();
- // bean_trace.clear();
- }
- cout << "\nDecompression check..." << flush;
- cout << "SUCCESS!\n" << flush;
- cout << "One more second..\n" << flush;
- cout << "\nBuffer Written... Exiting..\n";
- in.close();
- out.close();
- printf("*");
- return 0;
- }
- int main() {
- string outfile = "";
- string infile = "";
- string DC = "1";
- printf("Enter <C> or <D> to compress or decompress ");
- cin >> DC;
- printf("\nInput File: ");
- cin >> infile;
- ifstream in;
- in.open(infile.c_str(), std::ios::in | std::ios::binary);
- if (in.fail())
- return -1;
- printf("\nOutput File: ");
- cin >> outfile;
- ofstream out;
- out.open(outfile.c_str(), std::ios::out);
- if (out.fail())
- return -1;
- if ((DC=="c") || (DC=="C"))
- bool f=n.compress(in, out);
- if ((DC=="d") || (DC=="D"))
- bool f=n.uncompress(in, out);
- printf("\nProgram Execution Done.");
- n.~S_Rend();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement