// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// The simplest form of encryption is the rotation cipher
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// letter that that number of places away from it.
// letter that that number of places away from it.
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
// So if an offset value of 1 is chosen, each letter is replaced by the one after it
...
@@ -20,35 +20,35 @@ public class AssessmentPartThree {
...
@@ -20,35 +20,35 @@ public class AssessmentPartThree {
//This segment of the code creates a new instance of the StringBuilder called encoded for ease of access and fulfilment of the task
//This segment of the code creates a new instance of the StringBuilder called encoded for ease of access and fulfilment of the task
StringBuilderencoded=newStringBuilder();
StringBuilderencoded=newStringBuilder();
//This section of the code creates a new string which is equal the value of theChar
//This section of the code creates a new string which has the same value of theChar
Stringletter=String.valueOf(theChar);
StringLetter=String.valueOf(theChar);
//This section of the code creates a char called i and converts the string Letter to an array of characters
//This section of the code creates a char called a and converts the string Letter into an array of characters
//i is the selected character of the array
//a is the selected character of the array
for(chara:letter.toCharArray()){
for(chara: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 a is a letter then it will run the following code if not it stops
if(Character.isLetter(a)){
if(Character.isLetter(a)){
//this code checks to see if the character is upper case and if it is it then proceeds to work out the new letter once this is done it adds it to the StringBuilder Encoded
//this code checks to see if the character is upper case and if it is it then works out the new letter once completed it is automatically added to the String Builder encoded
if(Character.isUpperCase(a)){
if(Character.isUpperCase(a)){
encoded.append((char)('G'+(a-'G'+theOffset)%26));
encoded.append((char)('G'+(a-'G'+theOffset)%26));
//This code then runs if the character is a letter but isn't upper case therefore meaning it must be lower case, it proceeds to work out the new letter and then adds it to the StringBuilder Encoded
// the code the does the exact same check but for a lower case letter if once completed it again adds it to the string builder encoded
}else{
}else{
encoded.append((char)('g'+(a-'g'+theOffset)%26));
encoded.append((char)('g'+(a-'g'+theOffset)%26));
}
}
//If i isn't a letter then it will run this code
//If char a 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 a to the StringBuilder Encoded
encoded.append(a);
encoded.append(a);
}
}
}
}
//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 Completed and is set equal to the first value of the StringBuilder encoded
charFinished=encoded.charAt(0);
charCompleted=encoded.charAt(0);
//It then returns the char Finished
//It then returns the char Completed
returnFinished;
returnCompleted;
}
}
...
@@ -64,24 +64,24 @@ public class AssessmentPartThree {
...
@@ -64,24 +64,24 @@ public class AssessmentPartThree {
StringBuilderencoded=newStringBuilder();
StringBuilderencoded=newStringBuilder();
//The area of the code creates the integer a and sets its value to 0. And then says for each time a is less than the length of the String theMessage run the code below and increment i by one
//This segment of the code creates the integer a and for every time a is greater than the message length increment a by 1
for(inta=0;a<theMessage.length();a++){
for(inta=0;a<theMessage.length();a++){
//this sets the integer theOffset to be equal to theOffset divided by 26 plus 26
//this sets the integer theOffset to be equal to theOffset divided by 32 plus 32
theOffset=theOffset%26+26;
theOffset=theOffset%32+32;
//this creates a char called letter and sets it to be equal to theMessage character at i
//this creates a char called letter and sets it to be equal to theMessage character of a
//i is used to work out the char of the message
//a is also used to work out the char of the message
//for example if the value of i is 2 then it will look for the character at 2 in the message
//for example if the value of a is 2 then it will look for the character at 2 in the message
charletter=theMessage.charAt(a);
charletter=theMessage.charAt(a);
//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 using these values