Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- int main(int argc, string argv[])
- {
- if (argc != 2 || argv[1] == NULL )
- {
- return 1;
- }
- string keyword = argv[1];
- for (int j = 0, n = strlen(keyword); j < n; j++)
- {
- if ( !isalpha(keyword[j]) && argv[1] = NULL)
- {
- printf("Keyword must only contain letters A-Z and a-z\n");
- return 1;
- }
- else
- {
- string plaintext = GetString();
- for (int i = 0, n = strlen(plaintext); i < n; i++)
- {
- if (isalpha(plaintext[i]))
- {
- int code_lower = (keyword[j] - 'a');
- int code_upper = (keyword[j] - 'A');
- int letter = plaintext[i];
- int result_lower = (letter - 'a' + (code_lower %26)) + 'a';
- int result_upper = (letter - 'A' + (code_upper %26)) + 'A';
- if (islower(plaintext[i]))
- {
- if (result_lower > 'z')
- {
- int result_alphlower = (result_lower - 'z') + 96;
- printf("%c", result_alphlower);
- }
- else
- {
- printf("%c", result_lower);
- }
- }
- if (isupper(plaintext[i]))
- {
- if (result_upper > 'Z')
- {
- int result_alphupper = (result_upper - 'Z') + 64;
- printf("%c", result_alphupper);
- }
- else
- {
- printf("%c", result_upper);
- }
- }
- }
- else
- {
- printf("%c", plaintext[i]);
- }
- }
- printf("\n");
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement