elseif((index+theOffset)<0){//Otherwise if the index of ciphered character is less than zero, the index of the ciphered character is
index=letters.length+index+theOffset;//the sum of the length of the alphabet array, the index and theOffset.
}
else{
index=(index+theOffset)-letters.length;
else{//Otherwise if the calculated index of the ciphered character is greater than length of the alphabet array, the index of the ciphered character is
index=(index+theOffset)-letters.length;//subtracting the length of the alphabet from the sum of the index and theOffset.
}
}
if(index==-1){
returntheChar;
if(index==-1){//If the ciphered character cannot be calculated.
returntheChar;//Return the original character.
}
else{
returnletters[index];
else{//If the ciphered character can be calculated.
returnletters[index];//Return the character at the new index.
}
}
...
...
@@ -65,12 +73,12 @@ public class AssessmentPartThree {
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
Stringmessage="";
Stringmessage="";//Initialises variable for the cipher text.
for(inti=0;i<theMessage.length();i++){
charcurrent=theMessage.charAt(i);
charnewChar=enryptedCharacter(current,theOffset);
message=message+newChar;
for(inti=0;i<theMessage.length();i++){//Iterates through the plaintext string.
charcurrent=theMessage.charAt(i);//Gets the character at the current index.
charnewChar=enryptedCharacter(current,theOffset);//Calls the encryptedCharacter function to calculate and return the encrypted character.
message=message+newChar;//Adds the new encrypted character to the cipher text string.