[Solved] My basic cipher based encryption method in C++ is not working properly, how can I fix it? [closed]


I suggest placing all your valid characters into a string, then using the % operator.

const std::string valid_characters = 
     "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
const unsigned int shift_offset = 13;

std::string::size_type position = valid_characters.find(incoming_character);
position = (position + shift_offset) % valid_characters.length();
char result = valid_characters[position];

You will have to check the position value because find will return std::string::npos if the character does not exist in the valid_characters string.

solved My basic cipher based encryption method in C++ is not working properly, how can I fix it? [closed]