Commit d9c9720f authored by Bran's avatar Bran

updated

parent 5f51bd4c
......@@ -56,32 +56,44 @@ public class AssessmentPartThree {
public String encryptedString(String theMessage, int theOffset)
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
StringBuilder string = new StringBuilder(); //creates an empty StringBuilder called String
char j ; // creates an empty char called j
for (int i = 0; i < theMessage.length(); i++) // creates a for loop that iterates until i is greater then the length of whatever is stored in the string "theMessage"
{
j = theMessage.charAt(i); // makes j equal to the i'th character of theMessage
StringBuilder strBuilder = new StringBuilder();
char x ;
for (int i = 0; i < theMessage.length(); i++)
if (Character.isLetter(j)) // if the value assigned to j is a letter runs the following
{
x = theMessage.charAt(i);
j = (char) (theMessage.charAt(i) + theOffset); // makes j a char equal to the i'th value of theMessage + the value of the offset
}
if (Character.isLetter(x))
if ((Character.isLowerCase(theMessage.charAt(i))) && j > 'z')
{
x = (char) (theMessage.charAt(i) + theOffset);
j = (char) (theMessage.charAt(i) - (theOffset - 26));
}
if ((Character.isLowerCase(theMessage.charAt(i))) && x > 'z' || (Character.isUpperCase(theMessage.charAt(i))) && x > 'Z')))
if (Character.isUpperCase(theMessage.charAt(i)) && j > 'Z')
{
j = (char) (theMessage.charAt(i) - (theOffset - 26));
}
if (Character.isUpperCase(theMessage.charAt(i)) && j < 'A')
{
x = (char) (theMessage.charAt(i) + theOffset);
j = (char) (theMessage.charAt(i) + (theOffset + 26));
}
if ((Character.isLowerCase(theMessage.charAt(i)) && < 'a' || (Character.isUpperCase(theMessage.chatTA))
if ((Character.isLowerCase(theMessage.charAt(i)) && j < 'a'))
{
j = (char) (theMessage.charAt(i) + (theOffset + 26));
}
string.append (j);
}
return string.toString(); // returns a string containing whatever is stored in the stringbuilder "string"
}
......@@ -92,6 +104,7 @@ public class AssessmentPartThree {
/* char[] buffer = theMessage.toCharArray();
......@@ -127,7 +140,7 @@ public class AssessmentPartThree {
*/
}
}
......
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