Skip to content

Instantly share code, notes, and snippets.

@touatily
Last active December 31, 2021 19:41
Show Gist options
  • Save touatily/797b88cb150b536d329f287afab804cd to your computer and use it in GitHub Desktop.
Save touatily/797b88cb150b536d329f287afab804cd to your computer and use it in GitHub Desktop.
#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);
}
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