Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A simple encryption method that is common in children's puzzles works as follows. Take the message you want to encrypt and remove all whitespace and

A simple encryption method that is common in children's puzzles works as follows. Take the message you want to encrypt and remove all whitespace and punctuation. Arrange the letters of in a rectangular grid from left-to-right, top-to-bottom. Extra space may be needed to fill the final row. Then take the encoded message to be the letters in the order from top-to-bottom, left-to-right. Decoding is done in a similar way.

An example demonstrates the scheme. Assume we wish to encode the messagecomputer science rocks!There are 20 letters so we will need a grid with 4 rows and 5 columns:

compu tersc ience rocks 

The encoded message is thenctiroeeomrncpsckuces.

Write a function that will encode a given message using a grid with the prescribed number of columns.

Python Code:

# TODO: encoding function

def encode(message, num_cols):

"""Encodes a message."""

return None

# DO NOT MODIFY BELOW THIS LINE

print(encode("computer science rocks!", 5))

print(encode("this message is top secret", 5))

print(encode("the package will be delivered at midnight", 6))

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions