0% found this document useful (0 votes)
6 views3 pages

Hailcaesar

aaaa

Uploaded by

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

Hailcaesar

aaaa

Uploaded by

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

/*

Andrew Koh

9/21/2023

AP CSP

Period 6

*/

//Libraries

#include <cs50.h>

#include <stdio.h>

#include <string.h>

#include <ctype.h>

#include <stdlib.h>

int main(int argc, string argv[])

// Check for the correct number of command-line arguments

if (argc != 2)

printf("Usage: %s key\n", argv[0]);

return 1;

// Convert the key from a string to an integer and check for non-numeric
input

int key;

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


{

if (!isdigit(argv[1][i]))

printf("Usage: %s key\n", argv[0]);

return 1;

key = atoi(argv[1]);

// Prompt the user for plaintext

string plaintext = get_string("plaintext: ");

// Encrypt and print the ciphertext

printf("ciphertext: ");

for (int i = 0, n = strlen(plaintext); i < n; i++)

if (isalpha(plaintext[i]))

char shift = isupper(plaintext[i]) ? 'A' : 'a';

printf("%c", (plaintext[i] - shift + key) % 26 + shift);

else

printf("%c", plaintext[i]);

printf("\n");
return 0;

You might also like