Methods of encrypting and decrypting text

Assignment Help Business Management
Reference no: EM131981374

For this project you will be writing methods of encrypting and decrypting text.

PART 1 - NORMALIZE TEXT

The first thing we will do is normalize our input message so that it's easier to work with.

Using a method called normalizeText() which does the following:

1. Removes all the spaces from your text

2. Remove any punctuation (. , : ; ' " ! ? ( ) )

3. Turn all lower-case letters into upper-case letters

4. Return the result.

The call

normalizeText("This is some "really" great. (Text)!?")

should return

"THISISSOMEREALLYGREATTEXT"

PART 2 - CAESAR CIPHER

Next we'll be writing a Caesar Cipher. The Caesar cipher is just about the simplest encryption algorithm out there. A Caesar encription "shifts" each individual character forward by a certain number or "key". Each letter in the alphabet is shifted to the letter in the alphabet that is "key" places past the original letter. With a shift value of +1, the string "ILIKEZOOS" would be rendered as "JMJLFAPPT."

Using a method called caesarify that takes two parameters. The first argument is a string you want to encrypt, and the second is an integer that contains the shift value or "key". The function should return a string, which is the input string encrypted with the Caesar cypher using the shift value passed in its second argument. You may assume that the input string is normalized.

  • Note that the alphabet "wraps around", so with a shift value of +1 the "Z" in ZOOS became an A.
  • You can also have negative shift values, which cause the alphabet to previous letters. With a -1 shift, the string "ILIKEAPPLES" would turn into "HKHJDZOOKDR."

We will provide you with a function called shiftAlphabet. This function takes one argument, an integer to specify the shift value, and returns a string, which is the uppercase alphabet shifted by the shift value. So if you call shiftAlphabet(2), you will get back the following string: "CDEFGHIJKLMNOPQRSTUVWXYZAB"

Here is the implementation for shiftAlphabet, which you can just paste into your java file:

public static String shiftAlphabet(int shift) {

   int start = 0;

   if (shift < 0) {

       start = (int) 'Z' + shift + 1;

   } else {

       start = 'A' + shift;

   }

   String result = "";

   char currChar = (char) start;

   for(; currChar <= 'Z'; ++currChar) {

       result = result + currChar;

   }

   if(result.length() < 26) {

       for(currChar = 'A'; result.length() < 26; ++currChar) {

           result = result + currChar;

       }

   }

   return result;

}

PART 3 - CODEGROUPS

Traditionally, encrypted messages are broken into equal-length chunks, separated by spaces and called "code groups."

Using a method called groupify which takes two parameters. The first parameter is the string that you want to break into groups. The second argument is the number of letters per group. The function will return a string, which consists of the input string broken into groups with the number of letters specified by the second argument. If there aren't enough letters in the input string to fill out all the groups, you should "pad" the final group with x's. So groupify ("HITHERE", 2) would return "HI TH ER Ex".

  • You may assume that the input string is normalized.
  • Note that we use lower-case 'x' here because it is not a member of the (upper-case) alphabet we're working with. If we used upper-case 'X' here we would not be able to distinguish between an X that was part of the code and a padding X.

PART 4 - PUTTING IT ALL TOGETHER

Using a function called encryptString which takes three parameters: a string to be encrypted, an integer shift value, and a code group size. Your method should return a string which is its cyphertext equivalent. Your function should do the following:

  • Call normalizeText on the input string.
  • Call obify to obfuscate the normalized text.
  • Call caesarify to encrypt the obfuscated text.
  • Call groupify to break the cyphertext into groups of size letters.
  • Return the result

PART 5 - HACKER PROBLEM - DECRYPT

This part is not required for course credit.

Using a method called ungroupify which takes one parameter, a string containing space-separated groups, and returns the string without any spaces. So if you call ungroupify("THI SIS ARE ALL YGR EAT SEN TEN CEx") you will return "THISISAREALLYGREATSENTENCE"

Now using a function called decryptString which takes three parameters: a string to be decrypted and the integer shift value used to encrypt the string, and returns a string which contains the (normalized) plaintext. You can assume the string was encrypted by a call to encryptString().

So if you were to call

String cyphertext = encryptString("Who will win the election?", 5, 3);

String plaintext = decryptString(cyphertext, 5);

... then you'll get back the normalized input string "WHOWILLWINTHEELECTION".

Reference no: EM131981374

Questions Cloud

What you are going to end up with is fairly lengthy document : What you're going to end up with is a fairly lengthy document, and in the end you should identify the one or two best forecasting models that you have utilized.
Prepare research paper on security engineering : You need to prepare research paper on Security Engineering. You need to make format changes in attached file
What type of disaster plan should organization have in place : Identify a health care facility in your area (Dallas TX). What type of disaster plan should this organization have in place?
What are some of the strategies that firms engage : What is the difference between adding value in the value chain and creating returns for shareholders?
Methods of encrypting and decrypting text : For this project you will be writing methods of encrypting and decrypting text.
Calculate rate that you would need to earn on year security : Calculate the rate that you would need to earn on the one-year security next year to be indifferent between these two investment opportunities.
Define and explain your companys target market : Analyze the types of consumers who will be drinking your beverage in demographic terms (i.e., age, education level, income, gender, ethnic group, etc.).
Pseudocode for a collection manager program : You will implement three classes: one for the main recipe items, one for the ingredients that are part of the recipe, and one for the entire collection
Create a timeline of all the significant labor legislation : Create a timeline of all the significant labor legislation passed in the 20th century using Word's Table feature.

Reviews

Write a Review

Business Management Questions & Answers

  Team consists of eight employees

Your team consists of eight employees: three are newly hired employees, five employees are male and three are female. Each employee has a diverse background. Your charge is to reach the goal of improving customer service by directing the team throu..

  How work events impact job satisfaction and job performance

Describe the affective events theory and explain how work events impact job satisfaction and job performance. Describe how you might use emotional intelligence to control mood and create a positive work environment in your branch.

  Discuss the potential costs of system to the organization

Discuss the potential costs of the system to the organization and how the system will help the company to increase their revenue.

  Role of business in the economy

Discuss the role of business in the economy. Compare and contrast the roles of for-profit and non-profit organizations in the economy.

  Explain advertisers can then create a profile of you

Explain Advertisers can then create a profile of you based on your browsing behavior as well as store your browsing history as long as they like.

  Project management case

Important note: Discussion questions in this course use a case study that is found in Doc Sharing area in the file named "Project Management Case.docx." It is strongly recommended that you read this case study before attempting an assignment. Also..

  Differentiate between transaction and translation risks

Answer each in 150-200 words, with one reference per question. 1.Differentiate between transaction and translation risks. Explain how these risks affect firms and investors2. Describe the product life cycle as a useful tool for managing products aft..

  Describe how you will measure progress toward your success

Describe how you will measure progress toward your success. Describe how being an innovation leader could potentially enable you to foster positive social change.

  Describe a business strategy and supporting business plan

Describe a business strategy and supporting business plan for a small business concept. Explain and analyze the necessary activities and key decisions to start

  What is a multi-valued dependency

What is a multi-valued dependency? How are multi-valued dependencies incorporated into the definition of fourth normal form (4NF)?

  Describe or to purchase the existing busines

Determine if it would make more sense to open the new business you describe or to purchase the existing business you selected. Explain your reasoning.

  Discuss the critical points within service delivery process

Identify and discuss the critical points within the service delivery process that are likely to have a significant bearing on the customer's experience.

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