0% found this document useful (0 votes)
17 views1 page

Caeser

Uploaded by

Yamna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Caeser

Uploaded by

Yamna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <cs50.

h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, string argv[])


{
if (argc != 2)
{
printf("Usage: ./caeser key\n");
return 1;
}

for (int i = 0; i < strlen(argv[1]); i++)


{
if (!isdigit(argv[1][i]))
{
printf("Usage: ./caeser key\n");
return 1;
}
}

int k = atoi(argv[1]);

string plaintext = get_string("Plaintext: ");


printf("Ciphertext: ");

for (int j = 0; j < strlen(plaintext); j++)


{
if (isupper(plaintext[j]))
{
printf("%c", (plaintext[j] - 65 + k) % 26 + 65);
}

else if (islower(plaintext[j]))
{
printf("%c", (plaintext[j] - 97 + k) % 26 + 97);
}

else
{
printf("%c", plaintext[j]);
}
}
printf("\n");
}

You might also like