The Caesar cypher encrypts text with user derfined key and text.
In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
int main ( int argc , string argv[] )
{
int key,save;
string s ;
key = atoi(argv[1]);
s = GetString();
if ( argc != 2 )
{
printf("prgram is yelling at you !!");
return 1 ;
}
for ( int i = 0 ; s[i]!='\0' ; ++i) // manipulation without storing character
{
if ( isalpha( s[i]) ) // checks whether input is in character set or not
{
if ( islower ( s[i] ) ) // FOR LOWER CASES
{
save = key % 24 ;
s[i] = s[i] + save ;
if ( s[i] > 'z' )
s[i] = 'a' + ( s[i] - 'z' -1 );
}
if ( isupper ( s[i] ) ) // FOR UPPER CASES
{
save = key % 24 ;
s[i] = s[i] + save ;
if ( s[i] > 'Z' )
s[i] = 'A' + ( s[i] - 'Z' -1 );
}
}
printf ( "%c" , s[i] );
}
return 0 ;
}
Facts:
:) caesar.c exists
:) caesar.c compiles
:( encrypts "a" as "b" using 1 a s key
\ expected output, but not "b"
:( encrypts "barfoo" as "yxocll" using 23 as key
\ expected output, but not "yxc"
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
\ expected output, but not "EDUIRR"
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
\ expected output, but not "FeVJss"
:( encrypts "barfoo" as "onesbb" using 65 as key
\ expected output, but not "srw"
:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
\ expected output, but not "adxp, em tqxxa!"
:( handles lack of argv[1]
\ expected output, not standard error of \ "/opt/sandbox50/bin/run.sh: line 31: 189..."