Guest User

Untitled

a guest
Jan 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #define MAX_PHRASE_LENGTH 100
  7.  
  8. void EncodePhrase(char *original, char *encoded);
  9. char EncodeCharacter(char c);
  10.  
  11. int main(void)
  12. {
  13.     char phrase[MAX_PHRASE_LENGTH];
  14.     char encoded[MAX_PHRASE_LENGTH];
  15.  
  16.     printf("Enter phrase to encode: ");
  17.     gets(phrase);
  18.  
  19.     EncodePhrase(phrase, encoded);
  20.  
  21.     printf("Encoded: %s\n", encoded);
  22.    
  23.     return 0;
  24. }
  25.  
  26.  
  27. void EncodePhrase(char *original, char *encoded)
  28. {
  29. //declaring variable
  30. int i = 0;
  31.  
  32.     // using a while loop to encode one character at a time
  33.     while ( original[i] != NULL) {
  34.        
  35.         // sending one character to be encoded
  36.         encoded[i] = EncodeCharacter(original[i]);
  37.        
  38.         // incrementing i
  39.         i++;   
  40.    
  41.     }
  42.  
  43.     // adding null to the end of encoded
  44.     encoded[i] = EncodeCharacter(original[i]);
  45.  
  46. }
  47.  
  48. char EncodeCharacter(char c)
  49. {
  50.  
  51.     // using an if statement to either add or minus 13 to get the correctly encode the character
  52.     if ((c>64) && (c<78)) {
  53.    
  54.         c = c + 13;
  55.     }
  56.  
  57.     else if ((c>77) && (c<91)) {
  58.    
  59.         c = c - 13;
  60.     }
  61.    
  62.     else if((c>96) && (c<110)) {
  63.    
  64.         c = c + 13;
  65.     }
  66.    
  67.     else if((c>109) && (c<123)) {
  68.    
  69.         c = c - 13;
  70.     }
  71.  
  72. return c;
  73. }
Add Comment
Please, Sign In to add comment