Ceaser Cipher Encryption Technique in C
// Ceaser Cipher Encryption technique
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void to_lower(char word[]);
void ceaser_cipher_encrypt(char word[], int shift);
int main(){
int shift;
char word[100];
printf("enter a word: ");
fgets(word, sizeof(word), stdin);
word[strcspn(word,"\n")] = '\0';
to_lower(word);
//printf("%s",word);
printf("enter shift no: ");
scanf("%d",&shift);
printf("\nCeaser Cipher Encrypted: \n>");
ceaser_cipher_encrypt(word, shift);
}
void to_lower(char word[]){
int len = strlen(word);
for(int i = 0; i<len; i++){
word[i] = tolower(word[i]);
}
}
void ceaser_cipher_encrypt(char word[], int shift){
int len = strlen(word);
for(int i = 0; i<len; i++) {
char ch = word[i];
if(isalpha(ch)){
ch = ((ch - 'a' + shift) % 26)+ 'a';
}
printf("%c",ch);
}
}
Comments
Post a Comment