fork download
  1. public class Caesar {
  2. public static final int ALPHASIZE = 26;
  3. public static final char[] alpha = {'A', 'B', 'C',
  4. 'D','E', 'F','G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
  5. 'R','S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  6. protected char[] encrypt = new char[ALPHASIZE];
  7. protected char[] decrypt = new char[ALPHASIZE];
  8.  
  9. public Caesar(){
  10.  
  11. for(int i = 0; i < ALPHASIZE; i++)
  12.  
  13. encrypt[i] = alpha[(i + 3) % ALPHASIZE];
  14.  
  15. for (int i = 0; i < ALPHASIZE; i++)
  16.  
  17. decrypt[encrypt[i] - 'A'] = alpha[i];
  18. }
  19.  
  20. // Encryption Methord
  21. public String encrypt(String secret){
  22.  
  23. char[] mess = secret.toCharArray();
  24.  
  25. for (int i = 0; i < mess.length; i++)
  26.  
  27. if (Character.isUpperCase(mess[i]))
  28.  
  29. mess[i] = encrypt[mess[i] - 'A'];
  30.  
  31. return new String(mess);
  32. }
  33.  
  34. // Decryption Methord
  35. public String decrypt(String secret){
  36.  
  37. char[] mess = secret.toCharArray();
  38.  
  39. for (int i = 0; i < mess.length; i++)
  40.  
  41. if (Character.isUpperCase(mess[i]))
  42.  
  43. mess[i] = decrypt[mess[i] - 'A'];
  44.  
  45. return new String(mess);
  46.  
  47. }
  48.  
  49. // Main Methord
  50. public static void main(String[] args) {
  51.  
  52. Caesar cipher = new Caesar();
  53.  
  54. System.out.println("Encryption order = " + new String(cipher.encrypt) );
  55.  
  56. System.out.println("Decryption order = " + new String(cipher.decrypt) );
  57.  
  58. String secret = "THE ENGLE IS IN PLA; MEET AT JOE'S";
  59.  
  60. secret = cipher.encrypt(secret);
  61.  
  62. System.out.println(secret);
  63.  
  64. secret = cipher.decrypt(secret);
  65.  
  66. System.out.println(secret);
  67. }
  68. }
  69.  
  70.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: class Caesar is public, should be declared in a file named Caesar.java
public class Caesar {   
       ^
1 error
stdout
Standard output is empty