# Sadly, the Caesar system is also weak. There are two ways that it c...

## Question

Sadly, the Caesar system is also weak. There are two ways that it can be broken. First, if you know the language of the message (such as English) then you can use character frequency analysis to break any encryption scheme that does simple substitutions, which is what Caesar effectively does. Additionally, since there are only 60 unique shift values, with modern computing it would be trivial for an enemy to hire a good coder to write a program that would try all 60 and determine which created a readable result. This brings us to Bellaso!

Giovan Battista Bellaso was an Italian lawyer in the 1500s who was quite adept at mathematics. He was also a secretary who explored cryptography as a way to securely transmit correspondences about state affairs!

One of the systems he developed was an enhancement of the shift cipher. Rather than use a single shift, it used many. These shifts were represented by a keyword. For example, imagine a message Computer Science and a keyword CMSC131. There are two parts to this cipher system as you will implement it:

The keyword is repeated until its length matches the length of the message - in this case, that would be CMSC131CMSC131CM

(NOTE: You will need to convert the keyword to uppercase letters if it has any lowercase letters before using it for the encryption.)

The character from the repeated keyword that lines up with a character in the message is used as the shift by making the shift be that character's UNICODE value minus the ASCII/UNICODE value of the first valid character in our range, which in this case is 32 (note that this ends up making the valid shift values go from 0 through 59)

Using the example:

Plain text: Computer Science

Keyword repeated: CMSC131CMSC131CM

Let's look at how we would encode the i. We would have first converted the lowercase i to an uppercase I using the .toUpperCase() method. The UNICODE value for I is 73. The shift keyword tells us that we'll be shifting according to the character 1 (note, the character 1 not the numeric integer 1). Note that that character 1 has the UNICODE value of 49, which according to the above rules tells us the shift amount will be 17 (49-32). Remember, this is because the ASCII/UNICODE value for the first valid character in our range is 32. So, 73+17 gives us 90, which is the UNICODE value for Z.

We now have a far more advanced cipher system that appears immune to frequency analysis (since different shifts are used for different positions, which means that in the above example, a & in the ciphertext represents a C from the plaintext at one point and a U from the plaintext at another point).

For this task, there are two methods to design and implement:

public static String toBellaso(String plaintext, String keyword)

and

public static String fromBellaso(String ciphertext, String keyword)

Each takes a String for the message text and another String for the cipher keyword. Your experience and learning from the earlier tasks will greatly inform your work on this one.

To prevent possible user error, any letters in the ciphertext passed into the fromBellaso method will need to be forced into uppercase even if they were lowercase as typed into the GUI.

After you have implemented the methods for this task and tested them and have passed all of the submit server tasks, you might want to think about how easy or hard this system would be to break.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public static String toBellaso(String plaintext, String keyword){

String cipherText = "";

if(plaintext != null && keyword != null){

plaintext = plaintext.toUpperCase();
String key = keyword;
if(keyword.length() < plaintext.length()){
int diff = plaintext.length() - keyword.length();
int repeat = diff/keyword.length();
for (int i=0; i<repeat; i++){
keyword += key;
}

diff = plaintext.length() - keyword.length();
if(diff > 0) {
keyword += key.substring(0, diff);
}
}

int maxShift = 60;
int minKey = 32;

int range = minKey +maxShift -1;

for(int i=0; i<plaintext.length(); i++){
int unicodeText = plaintext.charAt(i);
int unicodeKey = (keyword.charAt(i));
if (unicodeKey > range){...

By purchasing this solution you'll be able to access the following files:
Solution.java.

\$20.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.