Prepare a shift cipher

Assignment Help Programming Languages
Reference no: EM13324567

In cryptography, a Caesar cipher, also called a shift cipher, encrypts a plaintext string by shifting the letters by a fixed number of positions shift_by. For example, if shift_by=3, then a shifts to d, b to e, x to a, A to D, and Z to C. Note that lowercase letters ‘wrap around', as do uppercase letters. Only upper- and lower-case letters are shifted; all other characters, including whitespace, punctuation, and digits, encode as themselves. Write a class CaesarCipher that gets constructed on the value shift_by. Its encode method encodes a string by shifting letters by shift_by positions, and its decode method decodes an encoded string.

>> cipher_1 = CaesarCipher.new(1)
>> s = 'A man, a plan, a canal: Panama!'
=> "A man, a plan, a canal: Panama!"
>> s_encoded = cipher_1.encode(s)
=> "B nbo, b qmbo, b dbobm: Qbobnb!"
>> cipher_1.decode(s_encoded)
=> "A man, a plan, a canal: Panama!"
>> cipher_12 = CaesarCipher.new(12)
>> cipher_12.encode(s)
=> "M ymz, m bxmz, m omzmx: Bmzmym!"
>> cipher_12.decode (cipher_12.encode(s))
=> "A man, a plan, a canal: Panama!"
>> cipher_12.decode(s_encoded)
=> "P bpc, p eapc, p rpcpa: Epcpbp!"
# s_encoded constructed with shift_by=1; wrong decoder!

Reference no: EM13324567

Questions Cloud

Find the average translational kinetic energy : If 62.9 L of oxygen at 18.0°C and an absolute pressure of 2.28 atm are compressed to 56.5 L and at the same time the temperature is raised to 50.0°C, What is the average translational kinetic energy of a nitrogen molecule at STP
Describe two major international declarations : Describe two major international declarations which relate to the rights of all persons to live in an environment which is not harmful to humans. Describe the difference between sectoral and product pollution. In your response indicate how the 1982 C..
Ethical-global and ecommerce environment : From the textbook, Business Law: The ethical, global,and ecommerce environment (14th ed.), what are three of the Common Characteristics of Poor Decision Making, three ways of Resisting Requests to Act Unethically, and three ways you can choose to Lea..
The process of selling dairy to alice : Dell, in the process of selling his dairy to Alice, tells her it has been operating profitably for the last year and presents her with appropriate records to review. Alice reviews the records,
Prepare a shift cipher : In cryptography, a Caesar cipher, also called a shift cipher, encrypts a plaintext string by shifting the letters by a fixed number of positions shift_by.
Calculate the change in the length of the bridge : A small bridge is constructed of a single concrete slab which has a length of 14.5 m at 21.7 °C. Calculate the change in the length of the bridge if the temperature changes to 28.7 °C
Discuss the kinds of communication problems : Discuss the kinds of communication problems managers might face is the India working environment. How should they prepare for and deal with them?
Conflict is a normal part of most interpersonal relationship : You learned that conflict is a normal part of most interpersonal relationships. Understanding the principles of conflict, and how you respond to conflict, will help you to overcome conflict's possible negative consequences.
How many dependency exemptions will the bakers : How many dependency exemptions will the Bakers be entitled to claim for the year? Explain your answer

Reviews

Write a Review

Programming Languages Questions & Answers

  Design-write program to enter score repetition structure

Design and write a program that asks the user to enter five test scores using a repetition structure. The program should display the letter grade for each score and the average test score at the end of the program.

  Difference in systolic blood pressure among race categories

Verify if there is any difference in Systolic blood pressure among the Race categories and type of analysis is appropriate and why?

  Write a program to print average grade of student

Write a program that read the grades.txt file and then prints the average grade of male and female students and the number of passed students by using the functions.

  Write program to accept name and score of all batsmen

Write a program to accept name and score of all batsmen of a team and print them in the given manner: INPUT:names[]={nam1,nam2,nam3,nam4,nam5,nam6} & scores[]={48,65,73,10,90,84}

  Implicit unsafe type conversions-statements and expressions

Write a report using APA format for references that researches the definition of the language with respect to implicit unsafe type conversions in both assignment statements and expressions.

  Program which calculate and displays fifteen percent tip

Write a program which calculate and displays a 15 percent tip when the price of a meal is input by the user. (Hint: the tip is computed by multiplying the price of the meal by 0.15.).

  Program to divide string based on some delimiter string

StringTokenizer is a class in the java.util library that can divide a String based on some delimiter String (a delimiter is a separator). If the instruction StringTokener st = new StringTokenizer.

  Javascript function for cookie added to user-s computer

JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer. If same user attempts to fill out form second time.

  Write application to input numbers in one dimensional array

Use a one dimensional array to solve the following problem: Write an application that inputs five numbers, each between 10 and 100, inclusive.

  Calculate and display total fees and discount

Write a program to select type of student using an option button and capture total credit hours using a text box. Calculate and display total fees, discount (if any) and net total fees (after discount).

  A slip class file with indicated methods defined

A customer Class file with indicated Methods defined - A boat Class file with indicated Methods defined and a slip Class file with indicated Methods defined.

  Write function template which accepts array

Write a function template arraySum () which accepts array and number of values stored in it and returns the sum of those values.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd