Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Caesar cipher, also known as a shift cipher, is one of the classic form of encryption that were used historically. Each letter in the

The Caesar cipher, also known as a shift cipher, is one of the classic form of encryption that were used historically. Each letter in the original message (plaintext) is replaced with a letter corresponding to a certain number of letters up or down in the alphabet. In this way, a message that initially was quite readable, ends up in a form that cannot be understood at a simple glance. For example, here is the Caesar Cipher using a right rotation of 5 places (equivalent to a left shift of 21 places). The shift parameter is used as the key.

Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Cipher: FGHIJKLMNOPQRSTUVWXYZABCDEfghijklmnopqrstuvwxyzabcde

Obviously, if a different key is used, the cipher alphabet will be shifted a different amount.

When encrypting, looks up each letter of the message in the plain line and writes down the corresponding letter in the cipher line. The example below uses the key 5.

Plaintext: Procedural Programming vs Object Oriented Programming

Ciphertext: Uwthjizwfq Uwtlwfrrnsl ax Tgojhy Twnjsyji Uwtlwfrrnsl

The Caesar Cipher can be represented using modular arithmetic as follows.

Enc(x) = (x + n) mod 26

This means that the encryption of a letter x is equal to a right shift of x by n letters. The result of the process is then taken under modulo division, meaning that if a letter is shifted past the end of the alphabet, it wraps around to the beginning.

Now, you are given below a cipher text encrypted using Caesar Cipher.

Fhewhqccydw qdt shofjewhqfxo qhu vkd. Oek sqd tushofj jxyi cuiiqwu kiydw rhkju vehsu qjjqsa. Sxusa qbb feiiyrbu auoi kdjyb jxu sehhusj edu yi vekdt.

Where the period (.) and comma (,) symbols are not encrypted. Write a program to decrypt this message by exhaustively search over all possible 26 keys.

(Hint: Declare a character array and initialize it with the given Ciphertext, i.e.,

int cipher[]=Fhewhqccydw qdt shofjewhqfxo qhu vkd. Oek sqd tushofj jxyi cuiiqwu kiydw rhkju vehsu qjjqsa. Sxusai qbb feiiyrbu auoi kdjyb jxu sehhusj edu yi vekdt.

Then write a loop to shift the ciphertext array element-by-element.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions