Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include<cs50.h>
- # include<stdio.h>
- # include<string.h>
- # include<ctype.h>
- char ciphertext;
- char ascii;
- char character;
- char cliphertext;
- int main(int argc, string argv[])
- {
- if(argc == 2)
- {
- string k = argv[1];
- {
- for (int l = 0, m = strlen(k); l < m; l++)
- if (!isalpha(k[l]))
- {
- printf ("Please enter alpha.\n");
- return 1;
- }
- else
- {
- printf("Plaintext: ");
- string plaintext = get_string();
- for (int i = 0, n = strlen(plaintext); i < n; i++)
- {
- if (isalpha(plaintext[i]))
- {
- if(isupper(plaintext[i]) && isupper(k[l]))
- {
- printf("%c", (((plaintext[i] - 65) + (k[l] - 65)) % 26) + 65);
- }
- else if(isupper(plaintext[i]) && islower(k[l]))
- {
- printf("%c", (((plaintext[i] - 65) + (k[l] - 97)) % 26) + 65);
- }
- else if(islower(plaintext[i]) && islower(k[l]))
- {
- printf("%c", (((plaintext[i] - 97) + (k[l] - 97)) % 26) + 97);
- }
- else if(islower(plaintext[i]) && isupper(k[l]))
- {
- printf("%c", (((plaintext[i] - 97) + (k[l] - 65)) % 26) + 97);
- }
- }
- else
- {
- printf("%c", plaintext[i]);
- }
- }
- printf("\n");
- }
- }
- }
- else
- {
- printf("Error\n");
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement