diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:16:34 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:16:34 -0700 |
| commit | 81ba9eb66f8284d8760012973f84cdbe617ceb94 (patch) | |
| tree | 466432644e9e3fd66ee183ec53a1f10abb1b7faa /Bomb.java | |
Diffstat (limited to 'Bomb.java')
| -rw-r--r-- | Bomb.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Bomb.java b/Bomb.java new file mode 100644 index 0000000..955a43f --- /dev/null +++ b/Bomb.java @@ -0,0 +1,41 @@ +import java.io.*; + +public class Bomb { + public static final int START = 124; + public static final int CODE_LENGTH = 6; + + public static void defuse(String code) throws Exception { + if (code.length() != CODE_LENGTH) { + throw new Bomb.Explosion(); + } + + String curr = Integer.toHexString(CODE_LENGTH); + for (int i = 1; i < CODE_LENGTH; i++) { + curr = scramble(curr); + if (curr.charAt(1) != code.charAt(i)) { + throw new Bomb.Explosion(); + } + } + } + + private static String scramble(String secret) { + return Integer.toHexString(Integer.parseInt(secret, 16) * 0xA9 / 0b010011); + } + + public static void main(String[] args) throws Exception { + System.out.println(); + System.out.println("Bomb armed and ready for defusal."); + System.setOut(new PrintStream(new OutputStream() { public void write(int b) {} })); + + // defuse("21d74"); // TODO: Find the code, hurry! + defuse("000000"); + System.setOut(SYSTEM_OUT); + System.out.println("Bomb defused! You saved the day!"); + System.out.println(); + } + + public static final PrintStream SYSTEM_OUT = System.out; + private static class Explosion extends RuntimeException { + public Explosion() { super("BOOM"); } + } +} |
