// 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(chari:letter.toCharArray()){
for(chari: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
charFinished=encoded.charAt(0);
charFinished=encoded.charAt(0);
//It then returns the char Finished
//It then returns the char Finished
returnFinished;
returnFinished;
...
@@ -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
StringBuilderencoded=newStringBuilder();
StringBuilderencoded=newStringBuilder();
//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(inti=0;i<theMessage.length();i++){
for(inti=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