Exercise 2. String Spaces - 30 points Background Many applications require manipulation of text (strings in Python). String functions permits the programmer to quickly manipulate a string for some...


Exercise 2. String Spaces - 30 points


Background


Many applications require manipulation of text (strings in Python). String functions permits


the programmer to quickly manipulate a string for some programming reason.


Task


1. User inputs a string. No error checking is required.


2. Determine the length of the string without the spaces included, There a many ways to


accomplish this, but one nice way of doing this would be the following:


ˆ Split the string into constituent strings via the Python split() function.


ˆ Iterate over the constituent strings and find the length of each constituent string


via the Python len() function.


ˆ Sum the constituent string lengths to get the overall string length without spaces.


3. Print the original string and then the number of spaces within the string.




Exercise 3. Vigenere Cipher - 50 points


Background


As you may recall from class, code was given to encrypt plaintext via the Caesar cipher.


The Caesar cipher is named for Roman general Julius Caesar, who used it to communicate


with his generals during battle.


The Caesar cipher is a substitution cipher in which each letter in the plaintext is shifted


a certain number of places down the alphabet. For example, with a shift of 1, a letter A


would be replaced by the letter B, B would become C, and so on. Note that with a shift of


1, the letter Z would wrap around to first letter A.


As an example, if the plaintext is attack at dawn, with a shift of 2, the encrypted text


would be cvvcem cv fcyp. To convert the encrypted text back to the original plaintext, the


Caesar cipher would use a shift of -2 thus decrypting cvvcem cv fcyp to attack at dawn.


The Caesar cipher is rather easy to break, because in the English language, the letter E


is the most commonly used letter. Vowels (A, E, I, O, and U) are used more frequently than


consonants with consonants R, S, T, L, and N being the most used. Any frequency analysis


can easily piece together what the shift number is by analyzing the frequency of letters in


the encrypted text.


First described in 1553, the Vigenere cipher is a method of encrypting text using a series


of interwoven Caesar ciphers. From the Wikipedia article describing the Vigenere cipher,


2


one would need to input a key, which is repeated until the repeated key length is the same


length as the text to be encrypted. Iterating over the text and key, one sees that the shift is


essentially changing for each letter within text.


Task


Create a Vigenere cipher Python program utilizing the following steps:


1. Ask the user to enter a message (the text, or in the parlance of cryptography, the


plaintext). Use the Python input function.


2. Ask the user to enter a key. Again, use the Python input function. Please error check


that the key is valid. A valid key will consist only of letters and numbers.


3. Encrypt the plaintext with the Vigenere cipher and print the encrypted message to the


screen. Only encrypt letters and numbers. Any non-letters or non-numbers should be


kept unaltered.


4. Decrypt the encrypted message back to a plaintext message and print the plaintext to


the screen.
Sep 14, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here