Last active
December 31, 2021 19:41
-
-
Save touatily/797b88cb150b536d329f287afab804cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ceasar.h" | |
void caesarEnc(const char * message, short key, char * ciphertext){ | |
unsigned int i = 0; | |
short rang; | |
while( message[i] != '\0'){ | |
if( ( message[i] >= 'a') && (message[i] <= 'z') ){ | |
rang = (message[i] - 'a' + key) % 26; | |
if( rang < 0) rang += 26; | |
ciphertext[i] = 'a' + rang; | |
} | |
else if(( message[i] >= 'A') && (message[i] <= 'Z')){ | |
rang = (message[i] - 'A' + key) % 26; | |
if( rang < 0) rang += 26; | |
ciphertext[i] = 'A' + rang; | |
} | |
else { | |
ciphertext[i] = message[i]; | |
} | |
i++; | |
} | |
ciphertext[i] = '\0'; | |
} | |
void caesarDec(const char * ciphertext, short key, char * plaintext){ | |
caesarEnc(ciphertext, -key, plaintext); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void caesarEnc(const char * message, short key, char * ciphertext); | |
void caesarDec(const char * ciphertext, short key, char * plaintext); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment