Commit 51ae5ee1 authored by Karrthus's avatar Karrthus

Completed futher work

parent 5bcb98a6
public class AssessmentPartThree {
// The simplest form of encryption is the rotation cipher (also known as Caeser's Cipher)
// An offset value is chosen to encrypt a message. Each letter is replaced by the
// letter that that number of places away from it.
......@@ -8,6 +9,8 @@ public class AssessmentPartThree {
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
public char enryptedCharacter(char theChar, int theOffset)
{
// 05 - encryptedCharacter
......@@ -17,6 +20,7 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
String lowerbet = "abcdefghijklmnopqrstuvwxyz";
String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
......@@ -30,29 +34,79 @@ public class AssessmentPartThree {
return newnumber;
}
if (theChar == capitalbet.charAt(i))
{
char newnumber = capitalbet.charAt(theOffset +i);
return newnumber;
}
char newnum = lowerbet.charAt(theOffset+i);
return newnum;
}
char newnumber = theChar;
return newnumber;
char newnumber = theChar;
return newnumber
;
}
}
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
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
String alphabeto = "abcdefghijklmnopqrstuvwxyz";
String CAPSalphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char newnum = 0;
char[] theChar = theMessage.toCharArray();
for (int x = 0; x < theMessage.length(); x++) {
for (int i = 0; i < alphabeto.length(); i++) {
if (theChar[x] == alphabeto.charAt(i)) {
newnum = alphabeto.charAt(theOffset+i);
}
if (theChar[x] == CAPSalphabet.charAt(i)) {
newnum = CAPSalphabet.charAt(theOffset+i);
}
}
theChar[x] = newnum;
System.out.println(theChar[x]);
}
String output = Arrays.toString(theChar);
System.out.println(output);
return "Encryptred message";
}
}
}
}
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