Commit fae474be authored by benn.robinson's avatar benn.robinson

Update AssessmentPartThree.java

parent 7a54ec0d
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)
...@@ -17,16 +16,64 @@ public class AssessmentPartThree { ...@@ -17,16 +16,64 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case // Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged // Any other characters are returned unchanged
return 'a'; char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; // creates an array which has each letter of the alphabet
int letterPlace = 0; //creates an int and the value is 0
theChar = Character.toLowerCase(theChar); //makes theChar equal to the lowercase value of theChar
boolean upperCase = Character.isUpperCase(theChar); // makes it equal to the uppercase value of theChar
if (Character.isLetter(theChar))
{
if (theOffset < 0)
{
theOffset = theOffset + 26;
}
if (theOffset > alphabet.length) // if the value of theOfset is greater than the length of the string alphabet
{
theOffset = theOffset - 26;
}
else
{
theChar = alphabet[theOffset];
}
}
else
{
return theChar;
}
for (int i = 0 ; i < alphabet.length; i++) // creates a 'for' loop that runs as long as 'i' is less than the length of the array string alphabet
{
if (theChar == alphabet[i])
{
theOffset = theOffset + i;
}
}
if (upperCase)
{
theChar = Character.toUpperCase(theChar); //makes thechar equal to the uppercase value of thechar
}
return theChar;
} }
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
{ {
// 06 - encryptedMessage // 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to // Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset // return the encrypted version of theMessage using theOffset
return "Encryptred message"; String output = "";
for (char letter : theMessage.toCharArray()) //creates a 'for' loop that iterates the char "letter" through theMessage.tochararray
{
output = output + letter;
letter = enryptedCharacter( letter, theOffset); // makes letter equal to the amount which has been obtained while running theMessgae through the encrypted character method above
} }
return output;
} }
}
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