YOUR TASK: Implement a function enc (msg: str, key: int) -> strthat takes a message string msg and a key key, 1< key

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
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:
COmmo
se in
nc0 m|m
gree i
th
e
a
n
u
d
e
W
h
a
t
e
r
1
d
с а
1
1
W
i
d
m
3
Transcribed Image Text: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: COmmo se in nc0 m|m gree i th e a n u d e W h a t e r 1 d с а 1 1 W i d m 3
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 an x, we simply
skip over it onto the next column. The resulting encrypted string is
Csngalioecrtdsm_oedmimetcoonm_hamn_oiel ans lsnwse_dwo_nuehrw
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) == 'acb'
• enc("monosodium glutamate", 7)=='mitouanmmo asgtoledu'
• enc("polylogarithmicsubexponential", 3)=='pygimseonaolatiuxntllorhcbpei'
Transcribed Image Text: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 an x, we simply skip over it onto the next column. The resulting encrypted string is Csngalioecrtdsm_oedmimetcoonm_hamn_oiel ans lsnwse_dwo_nuehrw 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) == 'acb' • enc("monosodium glutamate", 7)=='mitouanmmo asgtoledu' • enc("polylogarithmicsubexponential", 3)=='pygimseonaolatiuxntllorhcbpei'
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education