Skip to content

Instantly share code, notes, and snippets.

@51enra
Created November 19, 2019 13:34
Show Gist options
  • Save 51enra/1c1fe9e729d7105abed0b08702336d60 to your computer and use it in GitHub Desktop.
Save 51enra/1c1fe9e729d7105abed0b08702336d60 to your computer and use it in GitHub Desktop.
Quest 5: Decipher secret messages
public class Decipherer {
public static String decrypt(String encryptedText) {
final int STARTINDEX = 5;
int codeLength = encryptedText.length()/2;
encryptedText = encryptedText.substring(STARTINDEX, STARTINDEX + codeLength).replace("@#?", " ");
// convert String to character array
// by using toCharArray
char[] decryptedCharArray = encryptedText.toCharArray();
int textLen = decryptedCharArray.length;
for (int i = 0; i < textLen/2; i++) {
char swap = decryptedCharArray[i];
decryptedCharArray[i] = decryptedCharArray[textLen-i-1];
decryptedCharArray[textLen-i-1] = swap;
};
return new String(decryptedCharArray);
}
public static void main(String[] args) {
String secret1 = "0@sn9sirppa@#?ia'jgtvryko1";
String secret2 = "q8e?wsellecif@#?sel@#?sel@#?setuotpazdsy0*b9+mw@x1vj";
String secret3 = "aopi?sedohtém@#?sedhtmg+p9l!";
System.out.println("Meldung 1:" + decrypt(secret1));
System.out.println("Meldung 2:" + decrypt(secret2));
System.out.println("Meldung 3:" + decrypt(secret3));
}
}
Meldung 1:j'ai appris
Meldung 2:tes les les ficelles
Meldung 3:des méthodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment