C

Caesar Cipher Program in C

In this tutorial, we are going to see how to use the Caesar cipher to encrypt a message. Caesar’s cipher, also known as Shift Cipher, is one of the oldest and simplest forms of message encryption. This is a type of substitution cipher in which each letter of the original message is replaced by a letter corresponding to a number of letters shifted up or down in the alphabet.
100-multiple-choice-questions-in-c-programming100 Multiple Choice Questions In C Programming – Part 1This collection of 100 Multiple Choice Questions and Answers (MCQs) In C Programming : Quizzes & Practice Tests with Answer focuses on “C Programming”.  …Read More

Example Of Caesar Cipher
text = ABCD, Key = 10

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Right shift by 10, A is replaced by K
Right shift by 10, B is replaced by L
Right shift by 10, C is replaced by M
Right shift by 10, D is replaced by N

Output:

KLMN

 

 

Caesar Cipher Program in C
#include <stdio.h>

void cesar(char str[], int shift) {
  int i = 0;

  while (str[i] != '\0') {
    if (str[i] >= 'A' && str[i]<= 'Z') {
        char c = str[i] - 'A';
        c += shift;
        c = c % 26;
        str[i] = c + 'A';
    }
    i++;
  }
  printf("%s", str);
}

int main()
{
    char str[] = "ABCD";
    cesar(str, 10);
    return 0;
}

Output:

KLMN
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *