fork download
  1. class Krypte {
  2. public static void main (String [] args) {
  3. int i = 12345;
  4.  
  5. String k = Integer.toString(i);
  6. String G = secure(k.getBytes());
  7. System.out.println("Encrypted: " + G);
  8.  
  9. String U = secure(G.getBytes());
  10. System.out.println("Decrypted: " + U);
  11. int X = Integer.parseInt(U);
  12. System.out.println("As an int: " + X);
  13.  
  14. }
  15.  
  16. public static String secure(byte[] msg) {
  17. // Variables
  18. int outLength = msg.length;
  19. byte secret = (byte) 0xAC; // same as 10101100b (Key)
  20. // XOR kryptering
  21. for (int i = 0; i < outLength; i++) {
  22. // encrypting each byte with XOR (^)
  23. System.out.println("Byte before: " + msg[i]);
  24. msg[i] = (byte) (msg[i] ^ secret);
  25. System.out.println("Byte after: " + msg[i]);
  26. }
  27. return new String(msg);
  28. }
  29. }
Runtime error #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
Byte before: 49
Byte after: -99
Byte before: 50
Byte after: -98
Byte before: 51
Byte after: -97
Byte before: 52
Byte after: -104
Byte before: 53
Byte after: -103
Encrypted: �����
Byte before: -17
Byte after: 67
Byte before: -65
Byte after: 19
Byte before: -67
Byte after: 17
Byte before: -17
Byte after: 67
Byte before: -65
Byte after: 19
Byte before: -67
Byte after: 17
Byte before: -17
Byte after: 67
Byte before: -65
Byte after: 19
Byte before: -67
Byte after: 17
Byte before: -17
Byte after: 67
Byte before: -65
Byte after: 19
Byte before: -67
Byte after: 17
Byte before: -17
Byte after: 67
Byte before: -65
Byte after: 19
Byte before: -67
Byte after: 17
Decrypted: CCCCC