Commit 5f51bd4c authored by Bran's avatar Bran

almost complete

parent 51ae5ee1
import java.util.Arrays;
public class AssessmentPartThree {
......@@ -21,92 +22,117 @@ public class AssessmentPartThree {
// Any other characters are returned unchanged
String lowerbet = "abcdefghijklmnopqrstuvwxyz";
String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < lowerbet.length();i++)
{
if (theChar == lowerbet.charAt(i));
{
char newnumber = lowerbet.charAt(theOffset + i);
return newnumber;
}
if (theChar == capitalbet.charAt(i))
{
char newnum = lowerbet.charAt(theOffset+i);
return newnum;
}
String lowerbet = "abcdefghijklmnopqrstuvwxyz"; //creates a string containing all the letter of the alphabet in lowercase
String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // creates a string containing all the letters of the alphabet in uppercase
for (int i = 0; i < lowerbet.length(); i++) // creates a for loop that declares a variable called I, then iterates until i is greater than the length of the string lowerbet (in this case it would be 26)
{
if (theChar == lowerbet.charAt(i)) // creates an if statement that triggers if the character in theChar is equal to the ith value of the string lowerbet
{
char newnumber = lowerbet.charAt(theOffset + i); // assigns character equal to the character at the value of offset + the value of I of the string lowerbet to a char called newnum
return newnumber; // returns the value of newnum
}
if (theChar == capitalbet.charAt(i)) // if the value of theChar is equal to the i'th character of the string capitalbet
{
char newnumber = capitalbet.charAt(theOffset + i); // assigns character equal to the character at the value of offset + the value of i
return newnumber; //returns the value of newnum
}
}
char newnumber = theChar; // assigns the value of theChar to newnum
return newnumber; // returns the value of newnum
}
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]);
StringBuilder strBuilder = new StringBuilder();
char x ;
for (int i = 0; i < theMessage.length(); i++)
{
x = theMessage.charAt(i);
if (Character.isLetter(x))
{
x = (char) (theMessage.charAt(i) + theOffset);
if ((Character.isLowerCase(theMessage.charAt(i))) && x > 'z' || (Character.isUpperCase(theMessage.charAt(i))) && x > 'Z')))
{
x = (char) (theMessage.charAt(i) + theOffset);
if ((Character.isLowerCase(theMessage.charAt(i)) && < 'a' || (Character.isUpperCase(theMessage.chatTA))
}
}
}
/* char[] buffer = theMessage.toCharArray();
for (int i = 0; i < buffer.length; i++)
{
char letter = buffer[i];
letter = (char) (letter + theOffset);
if (('z' < letter) && ('Z' < letter))
{
letter = (char) (letter - 26);
}
else if (('a'< letter) && ('A' < letter))
{
letter = (char) (letter + 26);
}
else
{
letter = (char) (letter);
}
buffer[i] = letter;
}
String output = Arrays.toString(theChar);
return new String(buffer);
}
*/
}
}
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