Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python The ord function in Python takes a character and return an integer that represents that character. It does not matter what the integer representing

Python

The ord function in Python takes a character and return an integer that represents that character. It does not matter what the integer representing the character actually is, but what matters is this:

ord('a') is 1 less than ord('b'), so that:

x=ord('a') thisLetter = x+1 # thisLetter is the ord('b')

This is a powerful fact that is used in encryption techniques, so data transferred over the web is 'deciphered so it is unreadable to others.

To decipher data, we take a string and change it into another string by adding a constant to its ord value. See the book's Case study: word play.

To cipher and decipher data, we need two functions: one to take a string, and change it to something else. For this we need to use the ord function, and add the 'key' to result in a new string. For example, say x is one letter to be ciphered, and the key is 3. We can use:

Newx=ord(x)+3

Newx will be an integer. To find out what letter that integer represents you can use the chr function as in: chr(x).

Write a function cipher that takes a string and a key (integer). The function ciphers the string into another string and returns the new string. Note that when we reach 'z', and we want to add the key, we must 'roll' into the alphabet one more time, hence ord('z')+3 should give us ord('c').

Write another function to decipher (do the opposite of the previous function), given a string and a key, it returns the deciphered string.

From main, write code to get a string, and an integer as input, then call the cipher function and print its output. Then call the decipher function and display its output. The decipher output should match the original string.

For help on this see the book's Case study: word play. Add comments as needed but make sure to add top level comments.

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions