Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- #define MAX_PHRASE_LENGTH 100
- void EncodePhrase(char *original, char *encoded);
- char EncodeCharacter(char c);
- int main(void)
- {
- char phrase[MAX_PHRASE_LENGTH];
- char encoded[MAX_PHRASE_LENGTH];
- printf("Enter phrase to encode: ");
- gets(phrase);
- EncodePhrase(phrase, encoded);
- printf("Encoded: %s\n", encoded);
- return 0;
- }
- void EncodePhrase(char *original, char *encoded)
- {
- //declaring variable
- int i = 0;
- // using a while loop to encode one character at a time
- while ( original[i] != NULL) {
- // sending one character to be encoded
- encoded[i] = EncodeCharacter(original[i]);
- // incrementing i
- i++;
- }
- // adding null to the end of encoded
- encoded[i] = EncodeCharacter(original[i]);
- }
- char EncodeCharacter(char c)
- {
- // using an if statement to either add or minus 13 to get the correctly encode the character
- if ((c>64) && (c<78)) {
- c = c + 13;
- }
- else if ((c>77) && (c<91)) {
- c = c - 13;
- }
- else if((c>96) && (c<110)) {
- c = c + 13;
- }
- else if((c>109) && (c<123)) {
- c = c - 13;
- }
- return c;
- }
Add Comment
Please, Sign In to add comment