Question
Suppose you are given the following plain text: Members of the Senate and of the House of Representatives of the United States, I feel greatly
Suppose you are given the following plain text: Members of the Senate and of the House of Representatives of the United States, I feel greatly honored that you should have thus invited me to enter the United States Senate Chamber and address the representatives of both branches of Congress. The fact that my American forebears have for so many generations played their part in the life of the United States, and that here I am, an Englishman, welcomed in your midst, makes this experience one of the most moving and thrilling in my life, which is already long and has not been entirely uneventful. I wish indeed that my mother, whose memory I cherish, across the vale of years, could have been here to see. By the way, I cannot help reflecting that if my father had been American and my mother British instead of the other way around, I might have got here on my own. In that case this would not have been the first time you would have heard my voice. In that case I should not have needed any invitation. But if I had it is hardly likely that it would have been unanimous. So perhaps things are better as they are. (6 points each)
Store the text into a character variable ptext
Spilt the text into individual characters. [Hint: use strsplit()]
Store all characters in ptext into a character vector. [Hint: use unlist()]
Change all text to upper case. [Hint: Use toupper]
Remove all non-alphabetic characters. [Hint: use gsub()]
Tabulate the frequencies of all characters. [Hint: use table()]
Assign the following to a variable named key: ZGYHXIWJVKULTMSARBQCPDOENF. These correspond to the characters in the alphabet such that Z substitutes A, etc. Repeat steps (b) and (c) for the variable named key.
Assign all uppercase letters of the alphabet to a variable called alpha. Repeat steps (b) and (c) for the variable named alpha.
Find the number of characters in ptext. [Hint: use nchar()]
Using the variables alphai and key, encrypt ptext into a variable named ctext.
Put the steps in question 1 in a function that will take any text and a key as input and return the cipher text as output. Call this substitution_encrypt(). (20 points)
Create a second function called substitution_decrypt() that will take an encrypted text and a key as input and return the plain text as output. (20 points)
DO QUESTION 2 AND 3 ONLY
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started