Writing a Cipher
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
100%
Writing a Cipher

Transcribed Image Text:Hiding secrets from unwanted eyes has fascinated the humankind since ancient times. In the digital
age, this is usually done by cipher algorithms. A cipher algorithm takes a string message called the
plaintext and returns another string called the ciphertext that is (a) apparently hard to read, but (b)
can be converted back into the original plaintext message. Turning the plaintext into the ciphertext is
called encryption; reversing this process is called decryption.
In this task, you'll learn about a classic cipher called the transposition cipher and implement it.
Transposition Cipher. As the name suggests, the basic idea of the transposition cipher is to take the
message's symbols and jumble them up so that they become unreadable. The cipher decides how to
move the symbols around using what's known as the key, denoted by k. To encrypt a text of length
n, the key k is usually chosen to be a number between 2 and k – 1 (inclusive). The exact encryption
process is best described using an example.
Consider encrypting the text
Common_sense_in_an_uncommon_degree_is_what the_world_calls_wisdom
which contains 65 symbols, including spaces. The spaces are indicated by the symbol.
We'll use k = 10. First, we'll draw k boxes in a row-hence, drawing 10 boxes in our case.
Following that, we'll start filling the boxes from left to right using the symbols (letters and punctuation
marks) from the input text. When you run out of boxes, you create a new row of k boxes and continue
filling them until you accommodate the text entirely:
m
m
S
e
n
e i
co
gr|e
S
n
a
u
n
m
m
d
e
e
i
S
h
the
a
W
r
1
d
a
1
1
i
S
d
m
We include the x's in the last row only to remind ourselves that they aren't part of the input text and
should be ignored in later processing.
To complete the encryption, we'll read the symbol in the first (leftmost) column from top to bottom,
then the second column from top to bottom, so on so forth. Notice that when we hit
x, we simply
skip over it onto the next column. The resulting encrypted string is
Csngalioecrtdsm_oedmimetcoonm hamn,_oiel_ans_lsnwse_dwo_nuehrw

Transcribed Image Text:YOUR TASK: Implement a function enc (msg: str, key: int) -> str that takes a message string
msg and a key key, 1<key < len(msg), and returns a string representing the message encrypted using
the transposition cipher (as explained above). Here are some more examples:
enc ("abc",2)
• enc("monosodium glutamate", 7)=='mitouanmmo asgtoledu'
enc ("polylogarithmicsubexponential", 3)=='pygimseonaolatiuxntllorhcbpei'
'acb'
=%3=
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY