Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, string argv[])
- {
- while (argc!=2){
- printf("Usage: ./caesar key\n");
- return 1;
- }
- for (int w = 0; w<strlen(argv[1]); w++){
- char d = argv[1][w];
- if(d<48 || d>57)
- {
- printf("Usage: ./caesar key\n");
- return 1;
- }
- }
- int k = atoi(argv[1]);
- string a = get_string("plaintext: ");
- printf("ciphertext: ");
- for (int i = 0, n = strlen(a); i < n; i++)
- {
- char p = a[i];
- if (a[i] >= 'a' && a[i] <= 'z')
- {
- char c = p + k;
- if (c > 'z')
- {
- c=(c-'z')+('a'-1);
- }
- printf("%c", c);
- }
- else if (a[i] >= 'A' && a[i] <= 'Z')
- {
- char c = p + k;
- if (c > 'Z')
- {
- c=(c-'Z')+('A'-1);
- }
- printf("%c", c);
- }
- else {
- printf("%c", a[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement