Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Vigenre Cipher in C program : In cryptography, a shift cipher, also known as Caesar's cipher, is named after Julius Caesar (13 July 100 BC

"Vigenre Cipher" in C program : In cryptography, a shift cipher, also known as Caesar's cipher, is named after Julius Caesar (13 July 100 BC - 15 March 44 BC). The cipher uses a shift of the alphabet by a number to the left or right. Take the letters of the alphabet (we will restrict ourselves to the uppercase for now) and shift them by +5 characters, so that the letter 'A' becomes the letter 'F' ---->ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ This gives us: ABCDEFGHIJKLMNOPQRSTUVWXYZ (Plain Alphabet) FGHIJKLMNOPQRSTUVWXYZABCDE (Cipher Alphabet) Notice that the letter 'A' becomes 'F', which is 5 letters more. This is known as a right shift of 5. It is also the same as saying left shifted by -21 (If we are restricted to 26 characters). This will seem strange when looking at the plain alphabet and the cipher alphabet above. You can use this calculator to verify that a +5 shift is the same as a -21 shift: https://cryptii.com/caesar-cipher (External Site) Using this method, we can perform a simple encryption: "I NEED TO ENCRYPT THIS SENTENCE" becomes " N SJJI YT JSHWDUY YMNX XJSYJSHJ" To program this in the C language, we can assign number values to the letters starting with zero (for modular arithmetic) as follows: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 Let's define the shift using a letter. So a shift of 5 would be the key 'F' since we started our numbering at zero. Let's encrypt "HELLO" with a key of "F" or +5 shift, and we get "MJQQT" We can define the encryption using the formula: (Plain_Text_Value + Key_Value) mod Number_of_Letters_or_Symbols So in our example, encrypting "H" from "HELLO" with a key of "F", we get (7 + 5) % 26 = 12 % 26 = 12, or the letter 'M". To decrypt the "M" from "MJQQT" using the key "F", use the formula: (Encrypted_Text_Value - Key_Value) mod Number_of_Letters_or_Symbols: (12 - 5) % 26 = 7 % 26 = 7, or the letter 'H'. There is one issue when using the C Language modulus operator (%). If we decrypt 'B' using the key 'F', our formula gives us (1 - 5) % 26 = (-4) % 26 = -4 in the C language. We dont have a letter represented by -4 on the chart above. If we get a negative number when decrypting, just add the number of letters being used (26) to that number obtained. So (-4) becomes (-4 + 26) = 22, or the letter 'W'. Verify this (B -> W) for decrypting using the plain alphabet and cipher alphabet above. The Caesar Cipher may have been good for the time it was invented, but it is to easy to break, especially with computers. Simply shift the encoded message using all the keys 'A' to 'Z' and one of the results will reveal the decrypted message. The Vigenre cipher is a method of encrypting were the shift being used can vary from one letter to the next. So lets examine encryption of the word "HELLO" using the encryption key "BOOK". "HELLO" "BOOKB" Start by making the key as long as or longer than the message being encrypted. Repeat the key over again if needed. Since HELLO is 5 characters and BOOk is 4 characters, we start to repeat BOOK over again giving us BOOKB. Then take the first letter to encrypt. H=7, B=1, and we have 26 letters giving (7 + 1 ) % 26 = 8. So the letter H encrypts to 'I'. Let's do the next letter. E=4, O=14 giving us (4 + 14) % 26 = 18 % 26 = 18, or the letter 'S'. If we continue this procedure we will get "ISZVP" when "HELLO" is encrypted with "BOOK". You can verify this using the calculator at https://cryptii.com/vigenere-cipher (External Site). This cipher eluded attempts to break it for almost 300 years. Techniques to break it rely on the key repeating at some frequency. If the key is as long as the message to be encrypted, such as a paragraph or page out of a book or novel, and the same key is never used again, it becomes very difficult to break. This is known as a running key variant of the Vigenre cipher and at one time was considered unbreakable. Two spies that needed to exchange an encrypted message could agree in advance of a particular book, and a particular page that could be used for the key. The key could be as long as needed. There is a strong reason for digitizing all known books for use in cryptanalysis! Your assignment: 1) Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32, up to and including a ~ - Value 126. Therefore, the number of symbols is 95 (0 to 94), i.e. Mod 95. 6) If the key is shorter than the message, make sure the key repeats until it matches the length of the text to be transformed. 7) Print out the transformed (encrypted or decrypted) message. Tip. Given any printable character from the ASCII chart (32 to 126), then '?' - 32 gives a value from 0 to 94. Given any number from 0 to 94, adding 32 to that number gives the corresponding printable character.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Define Protocol and list the contents.

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago