#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Please enter 1 additional numeric Command-Line argument!\n");
return 1;
}
string plain;
int cipher = atoi(argv[1]);
int cipherMod;
printf("plaintext: ");
plain = get_string();
for (int i = 0, n = strlen(plain); i < n; i++)
{
if (i == 0) {
printf("ciphertext: ");
}
if (plain[i] >= 'A' && plain[i] <= 'Z')
{
if (cipher > 26)
{
cipherMod = cipher % 26;
plain[i] = plain[i] + cipherMod;
printf("%c", plain[i]);
}
else
{
plain[i] = plain[i] + cipher;
printf("%c", plain[i]);
}
}
if (plain[i] >= 'a' && plain[i] <= 'z')
{
if (cipher > 26)
{
cipherMod = cipher % 26;
plain[i] = plain[i] + cipherMod;
printf("%c", plain[i]);
}
else
{
plain[i] = plain[i] + cipher;
printf("%c", plain[i]);
}
}
}
printf("\n");
}
I have the issue, that the code works fine so far, but at the check a input of boofar with 23 or higher encryption and also the world, say hello is not being ciphered sucessfully! I see my Problem going down to the fact that for example the 'r' goes through the roof with a key of 23 because it leaves the boundary of the ASCII Table, but i don“t know how to exactly limit this yet...
Sry, for my english, it is not my native language ;)