Hi there.
I have an encryption method which handles a string char by char and converts it to base 32, then adds it onto the result string. However, it seems to completely replace the result string instead of adding onto the end of it. My code:
char *encrypt(std::string input, std::string key) {
char* result;
int lenIn = input.length();
int lenKey = key.length();
int i = 0;
int numKey;
while (i < lenIn) {
numKey = charCodeAt(key, i % lenKey);
long n = long(charCodeAt(input, i) + numKey);
ltostr(n, base32, 32);
if (i = 0) {
//Cannot concatenate a blank char* it seems
result = base32;
} else {
char* tempresult = result;
sprintf(result,"%s%s",tempresult,base32);
}
i++;
}
return result;
}
charCodeAt simply gets the unicode number in int format of the character entered. Can anyone help out?