fork download
  1. public class Main {
  2. public static void main(String[] args) {
  3. int[] ciphertext = {
  4. 102, 141, 142, 161, 148, 131, 158, 157, 120, 131,
  5. 126, 153, 130, 143, 154, 135, 118, 137, 148, 111,
  6. 116, 145, 134, 133, 118, 103, 136, 107, 138, 127,
  7. 102, 131, 194, 99, 114, 200, 202, 127, 120, 105,
  8. 126, 202, 108, 194, 198, 214, 222, 204, 116, 224,
  9. 194, 198, 202, 230, 166, 222, 216, 234, 232, 210,
  10. 222, 220, 210, 230, 194, 230, 198, 210, 210, 230,
  11. 234, 218, 222, 204, 194, 216, 216, 224, 216, 194,
  12. 210, 220, 232, 202, 240, 232, 198, 208, 194, 228, 230
  13. };
  14.  
  15. decrypt(ciphertext);
  16. }
  17.  
  18. public static void decrypt(int[] ct) {
  19. int length = ct.length;
  20. System.out.println("Ciphertext length: " + length + " characters");
  21. System.out.println("Testing possible keys from " + (length/2) + " to " + length);
  22.  
  23. for (int initialKey = length/2; initialKey <= length; initialKey++) {
  24. StringBuilder plaintext = new StringBuilder();
  25. boolean valid = true;
  26. int currentKey = initialKey;
  27.  
  28. for (int encrypted : ct) {
  29. boolean found = false;
  30. // Try all possible ASCII characters (32-126)
  31. for (int c = 32; c <= 126; c++) {
  32. if (c + (c % currentKey) == encrypted) {
  33. plaintext.append((char)c);
  34. found = true;
  35. break;
  36. }
  37. }
  38.  
  39. if (!found) {
  40. valid = false;
  41. break;
  42. }
  43.  
  44. currentKey++;
  45. }
  46.  
  47. if (valid) {
  48. System.out.println("\nFound valid decryption with initial key " + initialKey + ":");
  49. System.out.println(plaintext.toString());
  50. return;
  51. }
  52. }
  53.  
  54. System.out.println("No valid decryption found with standard ASCII characters.");
  55. }
  56. }
Success #stdin #stdout 0.13s 57864KB
stdin
Standard input is empty
stdout
Ciphertext length: 91 characters
Testing possible keys from 45 to 91

Found valid decryption with initial key 66:
3hismess<g?sAoMl;nJb:tCo;aDdEo3rac9des<i?e6ackof:pacesSolutionisasciisumofallplaintextchars