Write an algorithm that generates a Caesar cipher-a secret message in which each
ID: 3638109 • Letter: W
Question
Write an algorithm that generates a Caesar cipher-a secret message in which each letter is replaced by the one that is k letters ahead of it in the alphabet, in a circular fashion. For example, if k = 5, then the letter a would be replaced by the letter f, and letter x would be replaced by the letter c. The input to your algorithm is the text to be encoded, ending with the special symbol "$", and the value k. The output of your algorithm is the encoded text. Represent the algorithm as pseudo-code and as a Flow Control diagram.
Explanation / Answer
Step Operation 1.) Input Text and k 2.) Create a new list Code of same size as Text. 3.) set i to 1 4.) while Texti != ‘$’ repeat steps 4-11 5.) dist = Texti – ‘a’ 6.) code_dist = dist + k 7.) if ( code_dist < 26 ) 8.) Codei = ‘a’ + code_dist 9.) else 10.) Codei = ‘a’ + code_dist – 26 11.) set i to i+1 12.) print Code 13.) STOP Explanation: This algorithm assumes that alphabets ‘a’ –‘z’ have consecutive values assigned to them, for example, as in ASCII code. (see page 141 in Text, 5 th ed). Thus ‘b’ =’a’+1, ‘c’ = ‘a’ + 2 so on. Each character has a fixed distance from ‘a’. In step 5, we compute the distance of ith letter in text from ‘a’. In step 6, we add k to this value to get distance of coded letter. If this code_dist is less then 26, we can get the character by adding it to ‘a’ as in step 8. If code_dist is greater than 26, we wrap around. A code_dist of 27 would actually be distance1Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.