Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Caesar cipher A Caesar cipher is one of the simplest and most widely known encryption algorithms. In this algorithm, each letter of the plaintext is

Caesar cipher

A Caesar cipher is one of the simplest and most widely known encryption algorithms. In this algorithm, each letter of the plaintext is replaced by a different letter that is some fixed number of positions later in the alphabet. For example, with a shift number of 4, A would be replaced by E, B would become F, and so on.

Functions to Implement:

  • getCharacterForward(character, key) - return right-shifted character based on key

Function Details:

You already created a function that produces an alphabet: createAlphabet().

IMPORTANT: make sure that you use createAlphabet() as the helper function to generate the alphabet used by the encryption/decryption routines. You should be able to change the alphabet returned by createAlphabet() and all your other functions should still work correctly.

  • getCharacterForward(char, key) - return right-shifted character.
    • char is a single character from the alphabet
      • if char is not a single character, return None
    • key is an integer that indicates the number of steps to take
      • if key is not an integer, return -1

Upon receiving a character and a key this function gets the character to the right (forward) of char in the alphabet. To do so, it looks at the index of char in the alphabet and moves forward by the number of steps specified in the key.

For example, if you call this function with parameters b and 2 the result will be d. It is because d is 2 characters away from b. As another example, if you call this function with the input a and the total number of characters (len(createAlphabet()) the result will be a because you move it to the number of total characters and you will eventually land on the first character that you started the process on.

def getCharacterForward(char, key):

"""

Given a character char, and an integer key,

the function shifts char forward `key` steps.

Return the new character.

If `char` is not a single character, return `None`.

If `key` is not an integer, return -1.

"""

return "stub"

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

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

1. Explain how technology has changed the learning environment.

Answered: 1 week ago