fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String plainAlphabet = "abcdefghijklmnopqrstuvwxyz";
  11. String cipherAlphabet = "zyxwvutsrqponmlkjihgfedcba";
  12. String text = "Some sensitive text that only humans must be able to read";
  13.  
  14. String encodedText = encrypt(plainAlphabet, cipherAlphabet, text);
  15. System.out.println(encodedText);
  16. }
  17.  
  18. public static String encrypt(String plain, String cipher, String text) {
  19. plain = plain + plain.toUpperCase();
  20. cipher = cipher + cipher.toUpperCase();
  21.  
  22. String newText = "";
  23. for(int i=0; i<text.length(); i++) {
  24. char c = text.charAt(i);
  25. int index = plain.indexOf(c);
  26. if(index >= 0 && index < cipher.length()) {
  27. newText += cipher.charAt(index);
  28. } else {
  29. newText += c;
  30. }
  31. }
  32. return newText;
  33. }
  34. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
Hlnv hvmhrgrev gvcg gszg lmob sfnzmh nfhg yv zyov gl ivzw