ROT13 algorithm in C I am trying to learn C and I came across the ROT13 scrambling system used to store some passwords.

Assuming the user types everything in correctly (uses 1 argument, uses a string not an int, etc.) would this be correct/safe to use? Or is there anything at all that I am doing wrong you can point out to me (techniques, indentation, anything at all)?

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main(int argc, char** argv)
{
    char* word = argv[1];
    int key = 13;

    // all the letters in the first argument 
    for (int n = 0, len = strlen(word); n &lt; len; n++)
    {
        int currentLetter = word[n];

        char cipher = currentLetter + key;

        // make sure the next letter isn't over 26 or it isn't a ascii letter
        // if it is, do %26
        if ((currentLetter - 'a') + key &gt; 26)
        {
            key = (currentLetter - 'a') + key) % 26;
            cipher = 'a' + key;
        }

        printf("%c", cipher);
        // reset the key and do the next letter
        key = 13;
        }
    }
    printf("\n");
    return 0;
}
Test your program with a variety of inputs.
Include "abcdefghijklmnopqrstuvwxyz".

Have a look what happens for 'n'.
Always try to make sure you test low values, high values and edge cases.
'Wrapping round' is a classic edge case.

Then look at this line:

if ((currentLetter - 'a') + key &gt; 26)


This program only works for lower case 'passwords'.

You might look at the functions in #include &lt;ctype.h&gt; such as tolower(.) or islower(.) to extend to mixing upper and lower case.

NB Obviously ROT13 has no real cryptographic value of any kind.
I mention that because I have seen it (and things not better) used in applications.
You're doing this as a learning exercise. Right?