Commit 3de7a1a4 authored by norbertdajnowski's avatar norbertdajnowski

Commit 1

parent b9095079
Pipeline #316 failed with stages
...@@ -17,7 +17,43 @@ public class AssessmentPartThree { ...@@ -17,7 +17,43 @@ 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 encryptedC = (char) 0;
if ((theChar > 64) && (theChar < 91)) { //if statement to check if the character is between A-Z
if (theChar + theOffset > 90) { //if the offset goes over Z character
return encryptedC = (char) (((theChar + theOffset) - 90) + 64);
//return back to A and add rest of the offset there
}
else if (theChar + theOffset < 65) { //if the offset is negative and goes below A
return encryptedC = (char) (91 - (65 - (theChar + theOffset)));
//return to Z and take away rest of the offset
}
//else if the character doesn't cross under A or over Z then add offset to theChar normally
return encryptedC = (char)(theChar + theOffset);
}
if ((theChar > 96) && (theChar < 123)) { //if statement to check if the character is between a-z
if (theChar + theOffset > 122) { //if the offset goes over z character
return encryptedC = (char) (((theChar + theOffset) - 122) + 96);
//return back to a and add rest of the offset there
}
else if (theChar + theOffset < 97) {//if the offset is negative and goes below a
return encryptedC = (char) (123 - (97 - (theChar + theOffset)));
//return to z and take away rest of the offset
}
return encryptedC = (char)(theChar + theOffset);
} //else if the character doesn't cross under a or over z then add offset to theChar normally
return theChar; //return theChar unaffectedly if it is not a character A-Z or a-z
} }
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
...@@ -26,7 +62,15 @@ public class AssessmentPartThree { ...@@ -26,7 +62,15 @@ public class AssessmentPartThree {
// 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 EncryptedS = ""; //string for the final cipher-text
for (int i = 0; i <= theMessage.length() - 1; i++) { //iterate through all characters in the message
EncryptedS = EncryptedS + enryptedCharacter(theMessage.charAt(i), theOffset);
//add encrypted character onto the end of EncryptedS, using the enryptedCharacter method
}
return EncryptedS; //return the encrypted message
} }
} }
...@@ -34,7 +34,7 @@ class AssessmentPartThreeTest { ...@@ -34,7 +34,7 @@ class AssessmentPartThreeTest {
@CsvSource({ @CsvSource({
"hello,5,mjqqt", "hello,5,mjqqt",
"Java Coding,-3,Gxsx Zlafkd", "Java Coding,-3,Gxsx Zlafkd",
"dandelion,8,livlmtqmv", "dandelion,8,livlmtqwv",
"ktixevzout,-6,encryption" "ktixevzout,-6,encryption"
}) })
void testEncryptedString(String theMessage, int theOffset, String encMessage) { void testEncryptedString(String theMessage, int theOffset, String encMessage) {
......
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