Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, string argv[])
- {
- string arr[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
- int key = atoi(argv[1]);
- string plaintext = get_string("plaintext: ");
- char cpystr[64];
- for (int i = 0; i < sizeof(plaintext); i++)
- {
- strncpy(cpystr, plaintext, 64);
- }
- int h = 0;
- for (h = 0; cpystr[h]!='\0'; h++)
- {
- if(cpystr[h] >= 'a' && cpystr[h] <= 'z')
- {
- cpystr[h] = cpystr[h] - 32;
- }
- }
- char cipher[64];
- printf("ciphertext: ");
- for (int i = 0; i < strlen(cpystr); i++)
- {
- cipher[i] = strcmp(&cpystr[i], arr[0]) + key;
- int val = cipher[i];
- printf("%s", arr[val]);
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment