Advertisement
Guest User

Caesar code

a guest
Jun 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<cs50.h>
  4.  
  5. int main()
  6. {
  7.     char input[100], ch;
  8.     int i, key;
  9.    
  10.     printf("Enter a input to encrypt: ");
  11.     input = get_string;
  12.  
  13.    
  14.     printf("Enter key: ");
  15.     scanf("%d", &key);
  16.    
  17.     for(i = 0; input[i] != '\0'; ++i){
  18.         ch = input[i];
  19.        
  20.         if(ch >= 'a' && ch <= 'z'){
  21.             ch = ch + key;
  22.            
  23.             if(ch > 'z'){
  24.                 ch = ch - 'z' + 'a' - 1;
  25.             }
  26.            
  27.             input[i] = ch;
  28.         }
  29.         else if(ch >= 'A' && ch <= 'Z'){
  30.             ch = ch + key;
  31.            
  32.             if(ch > 'Z'){
  33.                 ch = ch - 'Z' + 'A' - 1;
  34.             }
  35.            
  36.             input[i] = ch;
  37.         }
  38.     }
  39.    
  40.     printf("Encrypted input: %s", input);
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement