Advertisement
thexiv

comb

Apr 5th, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. /*
  2.  * Kcracken v0.1
  3.  *
  4.  * Thank you to Dr. Dr. Morton,
  5.  * Whom without the help of his
  6.  * once in his classroom, I
  7.  * would not have reviled math
  8.  * as I now do -thexiv
  9. */
  10.  
  11. #include <bitset>
  12. #include <fstream>
  13. #include <iostream>
  14. #include <string>
  15. #include <iterator>
  16. #include <algorithm>
  17. #include <vector>
  18. #include <math.h>
  19. using namespace std;
  20.  
  21. class S_Rend {
  22.  
  23.     protected:
  24.     bitset<8> alpha, lambda, delta;
  25.  
  26.     vector<char> credit;
  27.     vector<int> bean_trace;
  28.     vector<int> lambdas;
  29.  
  30.     public:
  31.     int length = 0;
  32.  
  33.         S_Rend() { delta=0x00; lambda=0x00; alpha=0x00; delta=0x00; };
  34.     ~S_Rend() { };
  35.     long uncompress(ifstream&,ofstream&);
  36.     long compress(ifstream&,ofstream&);
  37.     long counter(long t);
  38.     long recover_data_point(long, long, int);
  39. } n;
  40.  
  41. /*+**- Project::Sailwinds -**+*/
  42.  
  43. // bean = counter       byte = lambda       ch = credited char
  44. long S_Rend::recover_data_point(long bean, long byte, int ch) {
  45.  
  46.     printf("*");
  47.  
  48.     if (length - bean == 1)
  49.         return 0;
  50.     if (credit.size() < 1 || bean_trace[bean_trace.size()-1] ^ credit[credit.size()-1] ^ lambdas[lambdas.size()-1] == byte) {
  51.         bean_trace.push_back(bean);
  52.         credit.push_back(ch);
  53.         byte ^= bean ^ ch;
  54.         lambdas.push_back(byte);
  55.         return ch ^ byte;
  56.     }
  57.     else
  58.         exit(0);
  59. }
  60.  
  61. long S_Rend::counter(long t) {
  62.     t+=1;
  63.     return t;
  64. }
  65.  
  66. long S_Rend::compress(ifstream& in, ofstream& out) {
  67.  
  68.     char last;
  69.     long long t;
  70.     bitset<8> fox = 0;
  71.     if (!(in.is_open()))
  72.     { return -1; }
  73.  
  74.     else {
  75.  
  76.     t= 0;
  77.     for_each (std::istreambuf_iterator<char>(in), \
  78.         std::istreambuf_iterator<char>(), \
  79.         [&] (char x) {
  80.         t=counter(t);
  81.         alpha = t;
  82.         delta = x;
  83.     // take delta ^ alpha (recurse ^ chars) from lambda == next lambda
  84.         fox = lambda;
  85.         lambda ^= (delta ^ alpha);
  86.         if (lambda.to_ulong() == 0)
  87.         { out << fox.to_ulong();
  88.             out << " " << t << " " << (char)(last) << endl;
  89.             t = 0;
  90.         }
  91.         last = x;
  92.     });
  93.  
  94.     printf("*");
  95.  
  96.     }
  97.  
  98.     if (out.is_open() && t > 0)
  99.     { out << fox.to_ulong();
  100.         out << " " << t << " " << (char)(last) << endl; }
  101.  
  102.     else { return -1; }
  103.     in.close();
  104.     out.close();
  105.     return 0;
  106. }
  107.  
  108. long S_Rend::uncompress(ifstream& in, ofstream& out) {
  109.  
  110.     short int i = 0, j = 0, h = 0, k = 0;
  111.     char ch;
  112.     long t = 0, mrc = 0;
  113.     int y = 0;
  114.     while (in >> t >> y >> ch) {
  115.         length = y;
  116.         printf("%u %u %c | ", y, t, ch);
  117.         mrc = 0;
  118.         int ess = 0, cnt = 1;
  119.         while (ess < length) {
  120.             //recover_data_point(y, t, ch);
  121.             i = j = 0;
  122.             if (ess%2 == 0) {
  123.                 i = h = 0;
  124.                 while (length > y+i) h ^= (int)i++;
  125.                 i = 0;
  126.                 while ((i ^ h) != mrc) (int)i++;
  127.                 --y;
  128.             }
  129.             else {
  130.                 i = 1;
  131.                 while (cnt > i) j ^= (int)i++;
  132.                 i = 0;
  133.                 while ((i ^ j) != mrc) (int)i++;
  134.                 ++cnt;
  135.             }
  136.             ess++;
  137.             printf("*");
  138.             credit.push_back((char)i);
  139.             t ^= (int)j;
  140.             t ^= (int)(i);
  141.             ch = i;
  142.             mrc = t;
  143.         }
  144.         i= credit.size();
  145.         while (i >= 0) {
  146.             char temp = credit[--i];
  147.             if (temp > 128)
  148.                 out << (char)(abs(temp));
  149.             else
  150.                 out << (char)(temp);
  151.         }
  152.         credit.clear();
  153.     //  bean_trace.clear();
  154.     }
  155.  
  156.     cout << "\nDecompression check..." << flush;
  157.     cout << "SUCCESS!\n" << flush;
  158.     cout << "One more second..\n" << flush;
  159.  
  160.     cout << "\nBuffer Written... Exiting..\n";
  161.     in.close();
  162.     out.close();
  163.     printf("*");
  164.     return 0;
  165. }
  166.  
  167. int main() {
  168.  
  169.     string outfile = "";
  170.     string infile = "";
  171.     string DC = "1";
  172.     printf("Enter <C> or <D> to compress or decompress ");
  173.     cin >> DC;
  174.  
  175.     printf("\nInput File: ");
  176.     cin >> infile;
  177.     ifstream in;
  178.     in.open(infile.c_str(), std::ios::in | std::ios::binary);
  179.  
  180.     if (in.fail())
  181.         return -1;
  182.  
  183.     printf("\nOutput File: ");
  184.     cin >> outfile;
  185.     ofstream out;
  186.     out.open(outfile.c_str(), std::ios::out);
  187.  
  188.     if (out.fail())
  189.         return -1;
  190.  
  191.     if ((DC=="c") || (DC=="C"))
  192.             bool f=n.compress(in, out);
  193.     if ((DC=="d") || (DC=="D"))
  194.             bool f=n.uncompress(in, out);
  195.  
  196.     printf("\nProgram Execution Done.");
  197.  
  198.  
  199.     n.~S_Rend();
  200.     return 0;
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement