Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!