I'm doing cs50 @ Edx.org. One of the problem sets was to take a key from the user and use caeser's algorithm to scramble the user input text. Not all that, but its the start to cryptology which underpin's cryptography. Its was also a learning curve into how to convert ASCII char into integer and converting back when shifting the letters.
#include <stdio.h>
#include <string.h>
#include <cs50.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, string argv[])
{
int k,Isum;
if (argc !=2)
{
return 1;
}
string p = GetString();
k = atoi(argv[1]);
k = (k%26);
for(int i=0, n=strlen(p);i<n;i++)
{
Isum = (p[i]+k);
if(toupper(p[i] && (Isum > 'Z')))
{
Isum = (Isum - 26);
}
if(tolower(p[i] && (Isum > 'z'))
{
Isum = (Isum -26);
}
if(isalpha(p[i]))
{
printf("%c", Isum);
}
else {
printf("%c", p[i]);
}
}
return 0;
}