Commit 07fb80e7 authored by ash.brett's avatar ash.brett

Update AssessmentPartThree.java

parent 229b95af
public class AssessmentPartThree { public class AssessmentPartThree {
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher) // The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
...@@ -28,21 +27,21 @@ public class AssessmentPartThree { ...@@ -28,21 +27,21 @@ public class AssessmentPartThree {
for (char i : letter.toCharArray()) { for (char i : letter.toCharArray()) {
//this states that if the char i is a letter then it will run the following code //this states that if the char i is a letter then it will run the following code
if (Character.isLetter(i)) { if (Character.isLetter(i)) {
//this code checks to see if the character is uppercase and if it is it then proceeds to workout the new letter once this is done it adds it to the stringBuilder Encoded //this code checks to see if the character is uppercase and if it is it then proceeds to work out the new letter once this is done it adds it to the StringBuilder Encoded
if (Character.isUpperCase(i)) { if (Character.isUpperCase(i)) {
encoded.append((char) ('A' + (i - 'A' + theOffset) % 26 )); encoded.append((char) ('A' + (i - 'A' + theOffset) % 26 ));
//This code then runs if the character is a letter but isnt uppercase therefore meaning it must be lower case, it proceds to work out the new letter and then adds it to the stringBuilder Encoded //This code then runs if the character is a letter but isn't uppercase therefore meaning it must be lower case, it proceeds to work out the new letter and then adds it to the StringBuilder Encoded
} else { } else {
encoded.append((char) ('a' + (i - 'a' + theOffset) % 26 )); encoded.append((char) ('a' + (i - 'a' + theOffset) % 26 ));
} }
//If i isnt a letter then it will run this code //If i isn't a letter then it will run this code
} else { } else {
//this adds the char i to the stringbuilder Encoded //this adds the char i to the StringBuilder Encoded
encoded.append(i); encoded.append(i);
} }
} }
//This section creates a char called Finished and sets it to equal the first value of the stringbuilder encoded //This section creates a char called Finished and sets it to equal the first value of the StringBuilder encoded
char Finished = encoded.charAt(0); char Finished = encoded.charAt(0);
//It then returns the char Finished //It then returns the char Finished
return Finished; return Finished;
...@@ -61,7 +60,7 @@ public class AssessmentPartThree { ...@@ -61,7 +60,7 @@ public class AssessmentPartThree {
//This section of the code creates a new instance of StringBuilder called encoded //This section of the code creates a new instance of StringBuilder called encoded
StringBuilder encoded = new StringBuilder(); StringBuilder encoded = new StringBuilder();
//The section of the code creates the int i and sets it value to 0. and then says for each time i is less than length of the String theMessage run the code below and increment i by one //The section of the code creates the int i and sets its value to 0. And then says for each time i is less than the length of the String theMessage run the code below and increment i by one
for (int i=0; i < theMessage.length(); i++) { for (int i=0; i < theMessage.length(); i++) {
//this sets the int theOffset to be equal to theOffset divided by 26 plus 26 //this sets the int theOffset to be equal to theOffset divided by 26 plus 26
theOffset = theOffset % 26 + 26; theOffset = theOffset % 26 + 26;
...@@ -72,10 +71,10 @@ public class AssessmentPartThree { ...@@ -72,10 +71,10 @@ public class AssessmentPartThree {
//This creates a new char called result and sets it to be equal to the result of the method enryptedCharacter //This creates a new char called result and sets it to be equal to the result of the method enryptedCharacter
//This section of code takes in the char letter and theOffset in order to run the method enryptedCharacter using these values //This section of code takes in the char letter and theOffset in order to run the method enryptedCharacter using these values
char Result = this.enryptedCharacter(letter, theOffset); char Result = this.enryptedCharacter(letter, theOffset);
//This section of code takes in the char Result and adds it to the stringBuilder encoded //This section of code takes in the char Result and adds it to the StringBuilder encoded
encoded.append(Result); encoded.append(Result);
} }
//This section of the code returns the value of the stringBuilder encoded in a string //This section of the code returns the value of the StringBuilder encoded in a string
return encoded.toString(); return encoded.toString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment