The constructor for the CaesarCipher class in Code Fragment 5.11 can be implemented with a two-line body
Question:
The constructor for the CaesarCipher class in Code Fragment 5.11 can be implemented with a two-line body by building the forward and backward strings using a combination of the join method and an appropriate comprehension syntax. Give such an implementation.
Transcribed Image Text:
1 class CaesarCipher: "'"' Class for doing encryption and decryption using a Caesar cipher.""" 3 def --init.-(self, shift): """ Construct Caesar cipher using given integer shift for rotation." encoder = [None] * 26 decoder = [None] * 26 for k in range(26): encoder[k] = chr((k + shift) % 26 + ord('A')) decoder[k] = chr((k – shift) % 26 + ord('A')) self._forward =!' join(encoder) self. backward = " join(decoder) 4 # temp array for encryption # temp array for decryption 10 %3D # will store as string # since fixed 11 12 13 def encrypt(self, message): """ Return string representing encripted message." return self.transform(message, self.-forward) 14 15 16 17 def decrypt(self, secret): """ Return decrypted message given encrypted secret." return self._transform(secret, self._backward) 18 19 20 21 def _transform(self, original, code): """ Utility to perform transformation based on given code string." msg = list(original) for k in range(len(msg)): if msg[k].isupper(): j = ord(msg|k]) – ord('A') msg[k] = codelj] return ' ' join(msg) 22 23 24 25 26 # index from 0 to 25 # replace this character 27 28 29 30 31 if --name-- '-_main__': cipher = CaesarCipher(3) 32 33 message = "THE EAGLE IS IN PLAY; MEET AT JOE'S." coded = cipher.encrypt(message) print('Secret: ', coded) 34 35 36 cipher.decrypt(coded) answer = print('Message:', answer) 37
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 63% (11 reviews)
Review the list comprehension syntax ...View the full answer
Answered By
Charles mwangi
I am a postgraduate in chemistry (Industrial chemistry with management),with writing experience for more than 3 years.I have specialized in content development,questions,term papers and assignments.Majoring in chemistry,information science,management,human resource management,accounting,business law,marketing,psychology,excl expert ,education and engineering.I have tutored in other different platforms where my DNA includes three key aspects i.e,quality papers,timely and free from any academic malpractices.I frequently engage clients in each and every step to ensure quality service delivery.This is to ensure sustainability of the tutoring aspects as well as the credibility of the platform.
4.30+
2+ Reviews
10+ Question Solved
Related Book For
Data Structures and Algorithms in Python
ISBN: 978-1118290279
1st edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Question Posted:
Students also viewed these Computer science questions
-
a. Carlys Catering provides meals for parties and special events. You created an Event class for the company. The Event class contains two public final static fields that hold the price per guest...
-
a. Sammys Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. You created a Rental class for the company. The Rental class contains two public...
-
Create a TaxReturn class with fields that hold a taxpayers Social Security number, last name, first name, street address, city, state, zip code, annual income, marital status, and tax liability....
-
Write a nonrecursive function that takes the first Node in a linked list as an argument and reverses the list, returning the first Node in the result.
-
A potential project has an initial capital investment of $100,000. Net annual revenues minus expenses are estimated to be $40,000 (A$) in the first year and to increase at the rate of 6.48% per year....
-
Indian Plastics make plastic buckets. An analysis of their accounting reveals: Required: (i). Find the break-even point. (ii). Find the number of buckets to be sold to get a profit of Rs. 30,000....
-
While the electromagnetic interaction between the photons and the charged electrons and positrons kept them in equilibrium with each other during the early universe, show that the direct...
-
The Omega Shoe Company manufactures a number of different styles of athletic shoes. Its biggest seller is the X Pacer running shoe. In 2008 Omega implemented a quality-management program. The...
-
Briefly describe the two Oracle Administrative Tools and talk about some of their administration usage: -SQL*Plus - Oracle Enterprise Manager Database Express (EM Express) Question2: Explain briefly...
-
A hospital in a developing nation is forced to manually put the flu shot vaccine into syringes. The recommended dosage for the flue shot is 0.5mL. The local health authorities define all syringes...
-
Our DynamicArray class, as given in Code Fragment 5.3, does not support use of negative indices with _ _getitem_ _. Update that method to better match the semantics of a Python list. Code Fragment...
-
Answer the previous question for the case when T is a proper binary tree with more than one node.
-
What is the reporting purpose of the statement of cash flows? Identify at least two questions that this statement can answer. Discuss.
-
In a big university, 70 % of the faculty members like to give plus and minus grades (such as B plus and C minus). The other 30 % of the faculty members do not like the plus and minus system. The...
-
What are some factors that affect a call options value?
-
Assume the tips received by five waitresses in a given weeknight are $25, $27, $28, $29, and $30. We draw two numbers randomly and take the average. Write the probability distribution of the sample...
-
Use a numerical integration routine on a graphing calculator to find the area in the first quadrant that is below the graph of And above the graph of y = 0.2x + 1.6. 6 = y 2 + 50 x
-
The newly produced 1992 Honda boasts 45 miles per gallon on the highway. Assume that the distribution of the miles per gallon is a normal distribution with a mean of 40 and a standard deviation of 5....
-
The partnership of Josephson, Ramirez, and Smith is being liquidated. All gains and losses are shared in a 3:2:1 ratio. Before liquidation their balance sheet looks as follows: Journalize the entries...
-
What is a content filter? Where is it placed in the network to gain the best result for the organization?
-
In what order are positions visited during a postorder traversal of the tree of Figure 8.6? 3 3 5 4
-
Justify Table 8.2, summarizing the running time of the methods of a tree represented with a linked structure, by providing, for each method, a description of its implementation, and an analysis of...
-
Draw an arithmetic expression tree that has four external nodes, storing the numbers 1, 5, 6, and 7 (with each number stored in a distinct external node, but not necessarily in this order), and has...
-
In 2006, e-Design was invited unexpectedly to participate in a design competition to provide new logos and new identity for Denmark's National Sports Team, a prestige client.What should the e-Design...
-
A golfer strikes the ball from the left and the parabola is shown. The height of the parabola is 7 metres and the maximum distance horizontal distance is approximately 40 metres. The distance the...
-
When a company is bouget out and migrates data to a new company's location, what cultural aspects of the change would the new company expect or experience when working with new database...
Study smarter with the SolutionInn App