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 <stdio.h>
#include <string.h>
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 < 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 > 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;
}