fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class SelfSynchronizingScrambler
  5. {
  6. private char key, shift_register;
  7.  
  8. private static int pickbit(char val, int index)
  9. {
  10. return ((val >> index)%2);
  11. }
  12.  
  13. public SelfSynchronizingScrambler() {}
  14.  
  15. public SelfSynchronizingScrambler(char key, char shift_register)
  16. {
  17. this.key = key;
  18. this.shift_register = shift_register;
  19. }
  20.  
  21. public void assignKey(char key) {this.key = key;}
  22. public void assignRegister(char shift_register) {this.shift_register = shift_register;}
  23.  
  24. public char keyValue() {return key;}
  25. public char registerValue() {return shift_register;}
  26.  
  27. public char scramble(char letter)
  28. {
  29. char output = 0;
  30. for (char i = 0; i < 8; ++i)
  31. {
  32. int newbit = pickbit(letter, 7-i);
  33. for (char j = 0; j < 8; ++j)
  34. {
  35. newbit ^= pickbit(this.key, 7-j) & pickbit(this.shift_register, 7-j);
  36. }
  37. output ^= (newbit << (7-i));
  38.  
  39. key = (char)((key >> 1) + (newbit << 7));
  40. }
  41. return output;
  42. }
  43.  
  44. public char descramble(char letter)
  45. {
  46. char output = 0;
  47. for(char i = 0; i < 8; ++i)
  48. {
  49. int oldbit = pickbit(letter, 7-i), scrambit = 0;
  50. for(char j = 0; j < 8; ++j)
  51. {
  52. scrambit ^= pickbit(this.key, 7-j) & pickbit(this.shift_register, 7-j);
  53. }
  54. output ^= ((scrambit^oldbit) << (7-i));
  55.  
  56. key = (char)((key >> 1) + (oldbit << 7));
  57. }
  58. return output;
  59. }
  60. };
  61.  
  62. public class Main
  63. {
  64.  
  65. public static void main (String[] args) throws java.lang.Exception
  66. {
  67. Scanner in = new Scanner(System.in);
  68. PrintWriter out = new PrintWriter(System.out);
  69.  
  70. SelfSynchronizingScrambler A = new SelfSynchronizingScrambler((char)5,(char)17);
  71. char scrambled;
  72.  
  73. while(in.hasNextInt())
  74. {
  75. scrambled = (char)in.nextInt();
  76. out.print(A.descramble(scrambled));
  77. }
  78.  
  79. out.flush();
  80. }
  81. }
Success #stdin #stdout 0.12s 29596KB
stdin
236 73 160 201 114 117 67 19 85 102 40 128 231 237 27 213 175 63 173 25 226 186 120 147 219 24 240 156 44 192 254 51 33 117 64 44 192 178 242 173 88 187 104 129 237 28 186 120 203
stdout
Base, base, it's cheeseburger 1. Can you hear me?