Simple encryption algorithm I originally made this as a way to use character strings as a base-256 number, but then realized that I could turn it into a method for encryption instead. The only thing is that since I'm using a basic addition algorithm for the encryption process, I'm iterating through a string by one character at a time (which seems kind of slow). Are there any other ways to improve the performance of this process or am I pretty much stuck with simple iteration?

Here's the encryption code:

void encodeStr(string encryptKey, string&amp; inputToEncrypt) {
    assert(minVal &lt; maxVal);
    if (inputToEncrypt.length() == 0) return;

    //preliminary remainder check initialization
    int remainder = minVal; //zero value
    int keyNumCount = 0;
    int keyCount = 0;

    //variables used to determine when to stop counting numbers
    size_t keyPos = 0;
    size_t count = 0;
    size_t countEnd = inputToEncrypt.length();

    //begin numerical addition. stop once the end of both strings is reached
    while (count &lt; countEnd) {
        //convert current characters to unsigned chars
        keyNumCount = encryptKey[keyPos];
        if (keyNumCount &lt; minVal) keyNumCount += minVal;

        keyCount = (count &lt; inputToEncrypt.length()) ? inputToEncrypt[count] : 0;
        if (keyCount &lt; minVal) keyCount += minVal;

        //take advantage of signed-char overflow to calculate current value
        remainder += keyNumCount + keyCount;
        inputToEncrypt[count] = remainder;

        //check if there is a remainder to be tabulated
        remainder = (remainder &gt; maxVal) ? 1 : 0;
        ++count;
        ++keyPos;
        if (keyPos == encryptKey.size()) keyPos = 0;

        //add 1 to the count if there is a remainder at the end of keyNum
        if (count == countEnd &amp;&amp; remainder != 0) {
            inputToEncrypt.push_back('\0');
            ++countEnd; //variables used to avoid integer overflow
        }
    }
}


And the decryption function:

void decodeStr(string decryptKey, string&amp; inputToDecrypt) {
    assert(minVal &lt; maxVal);
    if (inputToDecrypt.length() == 0) return;

    //preliminary remainder check initialization
    int remainder = minVal;
    int keyNumCount = 0;
    int keyCount = 0;

    //variables used to determine when to stop counting numbers
    size_t keyPos = 0;
    size_t count = 0;
    size_t countEnd = inputToDecrypt.length();

    //make sure the program exits before the number necomes negative
    while (count &lt; countEnd) {
        //convert current characters to unsigned chars
        keyNumCount = decryptKey[keyPos];
        if (keyNumCount &lt; minVal) keyNumCount += minVal;

        keyCount = inputToDecrypt[count];
        if (keyCount &lt; minVal) keyCount += minVal;

        //take advantage of signed-char overflow to calculate current value
        remainder += keyCount - keyNumCount;
        inputToDecrypt[count] = remainder;

        //check if there is a remainder to be tabulated
        remainder = (remainder &gt; maxVal) ? 1 : 0;
        ++count;
        ++keyPos;
        if (keyPos == decryptKey.size()) keyPos = 0;
    }
}
Since you key is const it would be nice to mark it as such (and avoid accidents of changing your key):

void encodeStr(string const&amp; encryptKey, string&amp; inputToEncrypt) {
//                    ^^^^^


To save the cost of the copy I would also make it a reference.

No idea what these are:

assert(minVal &lt; maxVal);


The extra set of variables seems like a good idea but actually makes the code harder to read as you need to understand what the variable represents:

size_t countEnd = inputToEncrypt.length();
while (count &lt; countEnd) {

// Simpler to

while (count &lt; inputToEncrypt.length()) {


When is this condition every going to fail and give you 0?

keyCount = (count &lt; inputToEncrypt.length()) ? inputToEncrypt[count] : 0;


If it was going to fail then you should have the same precautions on this:

inputToEncrypt[count] = remainder;


This is also bound to result in truncation of reminder. As inputToEncrypt as a string and thus each position is a char while remainder is the sum of 2 integers both greater than minval.

inputToEncrypt[count] = remainder;