-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.java
More file actions
26 lines (20 loc) · 701 Bytes
/
Copy pathhash.java
File metadata and controls
26 lines (20 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.Scanner;
public class hash {
public static byte xorHash(byte[] data) {
byte result = 0;
for (byte b : data) {
result ^= b;
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string to hash with XOR: ");
String input = scanner.nextLine();
byte[] bytes = input.getBytes();
byte hash = xorHash(bytes);
System.out.println("XOR Hash (decimal): " + (hash & 0xFF));
System.out.println("XOR Hash (hex): 0x" + Integer.toHexString(hash & 0xFF).toUpperCase());
scanner.close();
}
}