Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS151 Principles of Computer Science I - Fall 2017 LAB 12: Playfair Encryption The Playfair Cipber is an example of a key-based eneryption scheme, where

image text in transcribed
image text in transcribed
CS151 Principles of Computer Science I - Fall 2017 LAB 12: Playfair Encryption The Playfair Cipber is an example of a key-based eneryption scheme, where the encryption of a messagne depends on a secret key known only to the person encrypting the message the the person receiving and decrypting the message. The key can be a single word or an entire phrase or sentence. The Playfair cipher encrypts two letters at a time, making use of a 5 x 5 table constructed from the key (if the original messnge has an odd number of letters then you add an extra letter 'X' to the end of the messnge). The table is constructed as follows: starting in the upper-right hand corner and going row-wise you fill in the grid with the ketters of the key, skipping any reponted letter in the key. Once you are done, you fill in the remaining squares with the remaining letters of the alphabet in reverse. For example, if the lkey is the phrase To be, or not to be: that is the question:", the table would look like the following: Notice that the letters I and J always share the same square. Now, suppose we want to encrypt the message Trouble at base. This would first be split up into the digrams TR OU BL EA TB AS EX" (adding an X' at the end to get an even umber of letters) and each digram would be encrypted using the following rules: 1. If both letter are the same or are in the same row, then each letter moves one letter to the right. The first digram "TR" would be encrypted as "OT 2. If both letters are in the same column, then each lett ter moves down one square, wrapping around to the top if necessary. The first digram "OU" would be encrypted as "HV 3. Otherwise, both letters in the digram are in different rows and columns. You encrypt the first letter by using the letter in the same row as the first letter but in the same column as the second letter. You enerypt the second letter in a similar way, using the letter in the same row as the second letter but the same column as the first letter. The digram "BL" would be encrypted as "RP", and the digram "EA" would be enerypted as "BI (or "B.J") The entire encrypted message would be "OTHVRPBIOEINRY following three methods: public PlayfairCoderxxx(String k) - a constructor which takes the key as an argument. public String encrypt (String plaintext) a method that returus the encrypted OK, that was a lot. For this lab you are to write a class Playfaircoderxxx which has the the argument plaintext public String decrypt (String ciphertext) - a method that returns the decrypted version of the argument ciphertext. Finally, add a public static void main routine which prompts the user for a key and a string to encrypt, then uses a PlayfairCoderxxx object to encrypt the message and then decrypt it back. And if you're wondering, "Send more monkeys" get's encrypted as "IRIKVERTVEQTIMXL using the key phrase above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Convert 13 revolutions to (a) Radians (b) Degrees.

Answered: 1 week ago

Question

here) and other areas you consider relevant.

Answered: 1 week ago