Last active
November 2, 2015 21:04
-
-
Save apfeltee/c07f6e454c22f793993c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uses algos from https://benkurtovic.com/2014/06/01/obfuscating-hello-world.html | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <cmath> | |
#include <gmpxx.h> | |
template<typename Type> | |
void pv(const std::string name, const std::vector<Type>& vec) | |
{ | |
size_t i; | |
std::cout << name << " = {" << std::flush; | |
for(i=0; i<vec.size(); i++) | |
{ | |
std::cout << vec[i]; | |
if((i+1) != vec.size()) | |
{ | |
std::cout << ", "; | |
} | |
std::cout << std::flush; | |
} | |
std::cout << "};" << std::endl; | |
} | |
mpz_class s2num(const std::string& str) | |
{ | |
size_t i; | |
mpz_class sum; | |
std::vector<int> codes; | |
std::vector<mpz_class> temp; | |
sum = 0; | |
for(i=0; i<str.size(); i++) | |
{ | |
codes.push_back(str[i]); | |
} | |
for(i=0; i<codes.size(); i++) | |
{ | |
temp.push_back(codes[i] * std::pow(256, i)); | |
} | |
for(auto& n: temp) | |
{ | |
sum += n; | |
} | |
pv("codes", codes); | |
pv("temp", temp); | |
return sum; | |
} | |
std::string num2s(const mpz_class& num) | |
{ | |
if(num > 0) | |
{ | |
return (char(num.get_ui() % 256) + num2s(num / 256)); | |
} | |
return ""; | |
} | |
int main() | |
{ | |
std::string s = "Hello World!"; | |
auto a = s2num(s); | |
auto b = num2s(a); | |
std::cout << "a = " << a << std::endl; | |
std::cout << "b = " << b << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment