Skip to content

Instantly share code, notes, and snippets.

@dongho-jung
Created June 3, 2017 07:06
Show Gist options
  • Save dongho-jung/ef414a925201db3b8dc772c2ba0d6d0f to your computer and use it in GitHub Desktop.
Save dongho-jung/ef414a925201db3b8dc772c2ba0d6d0f to your computer and use it in GitHub Desktop.
Obfuscate string 2 double :3
#include <iostream>
#include <random>
using namespace std;
void obfuscate2double(const char obfuscatedString[], int stringCount, double*& obfuscatedDouble, int& doubleCount) {
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> pickRandom(3, 7);
int currentPosition = 0;
int sizePiece, sizeDouble = 0;
char* stringPiece = nullptr;
double** tempDouble = new double*[256];
double epsilon = numeric_limits<double>::min();
while (currentPosition < stringCount) {
sizePiece = stringCount - currentPosition < 7 ? stringCount - currentPosition : pickRandom(gen);
stringPiece = new char[sizePiece];
strncpy(stringPiece, obfuscatedString + currentPosition, sizePiece);
stringPiece[sizePiece] = '\0';
tempDouble[sizeDouble] = reinterpret_cast<double*>(stringPiece);
if (fabs(*(tempDouble[sizeDouble])) < epsilon) {
continue;
}
currentPosition += sizePiece;
sizeDouble++;
}
doubleCount = sizeDouble;
obfuscatedDouble = new double[sizeDouble];
for (int i = 0; i < sizeDouble; i++)
obfuscatedDouble[i] = *tempDouble[i];
}
int main() {
char* originalString = "Hello world! This is a test message.";
double* obfuscatedDouble;
int obfuscatedDoubleSize;
obfuscate2double(originalString, strlen(originalString), obfuscatedDouble, obfuscatedDoubleSize);
for (int i = 0; i < obfuscatedDoubleSize; i++)
printf("%.*e\t%s\n", DECIMAL_DIG, obfuscatedDouble[i], &obfuscatedDouble[i]);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment