Skip to content

Instantly share code, notes, and snippets.

@ymmuse
Last active November 26, 2015 05:38
Show Gist options
  • Save ymmuse/9e3bd85371e041e3bda3 to your computer and use it in GitHub Desktop.
Save ymmuse/9e3bd85371e041e3bda3 to your computer and use it in GitHub Desktop.
Simple protection ascii characters
//
// main.cpp
// protectedString
//
// Created by max on 11/26/15.
// Copyright © 2015 max. All rights reserved.
//
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
char token[5] = {0};
const char *str = argv[1];
int maxlen = strlen(str);
std::cout << "******** You should copy below code to your project: ********\n\n";
std::cout << "char ssss["<< maxlen+1<<"];\n";
std::cout << "sprintf(ssss, \"";
char *valstr = new char[32*1024*1024];
memset((void*)valstr, 0, 32*1024*1024);
int i = 1;
for (; i <= maxlen; i++) {
if ((i%4) == 0)
token[3] = str[i-1];
else
token[(i%4)-1] = str[i-1];
// std::cout << token << "\n";
if (i%4 ==0|| i==maxlen) {
uint32_t total = (*(uint32_t*)token);
int j = 0;
char ss[1024] ={0};
for (;j < 4; j++) {
if (token[j]==0)
break;
std::cout << "%c";
switch (j) {
case 0:
sprintf(ss, "%s,(char)((%u & 0x0000007F))", ss,total);break;
case 1:
sprintf(ss, "%s,(char)((%u & 0x00007F00)>>8)",ss, total);break;
case 2:
sprintf(ss, "%s,(char)((%u & 0x007F0000)>>16)",ss, total);break;
case 3:
sprintf(ss, "%s,(char)((%u & 0x7F000000)>>24)", ss, total);break;
}
}
sprintf(valstr, "%s %s", valstr, ss);
memset((void*)token, 0, 5);
}
}
std::cout << "\"" << valstr << ");\n\n\n\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment