I am working on making a simple program which allows rot13 encryption and decryption of files. I am starting small and I am working on making code to perform rot13 to and from on a char*. For some reason I can't have anything over size 4 put in the returned char. I think I may be misusing sizeof. Here is my code with the output it produces.
Code:
using std::string;
char* encrypt_string(const char *input){
size_t size = (sizeof(input) / sizeof(*input));
char *ret = new char[size + 1];
for(size_t i = 0; i < size + 1; ++i){
*(ret + i) = (*(input + i) + 13);
}
return ret;
}
char* decrypt_string(const char *out){
size_t size = (sizeof(out) / sizeof(*out));
char *ret = new char[size + 1];
for(size_t i = 0; i < size + 1; ++i){
*(ret + i) = (*(out + i) - 13);
}
return ret;
}
int main(){
char *orig = "goodbye";
size_t t = (sizeof(orig) / sizeof(*orig));
std::cout << t << std::endl;
char *s = encrypt_string(orig);
std::cout << s << std::endl;
size_t size = sizeof(s) / sizeof(*s);
std::cout << size << std::endl;
char *s1 = decrypt_string(s);
std::cout << s1 << std::endl;
}
output is
Perhaps it's something small that I am missing in my tired state, but help would be greatly appreciated.