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>
- int main(int argc, string argv[])
- {
- if(argc == 2)
- {
- for(int i = 0; i < strlen(argv[1]); i++)
- {
- if(!isdigit(argv[1][i]))
- {
- printf("Usage: ./caesar key");
- return 0 ;
- }
- }
- string pi = get_string("paintext: ");
- int size = strlen(pi);
- int k = atoi(argv[1]);
- char ci[size+1];
- ci[size] = '\0';
- for(int j = 0; j < size; j++)
- {
- ci[j] = (pi[j] + k) % 26;
- }
- printf("cliphertext: %s\n", ci);
- }
- else
- {
- printf("Usage: ./caesar key");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement