public class HashHelper { // Hash Function 0: Convertion of chars according to their position in word + some constant value public static String hash(String input) { String hashed = ""; int salt = 8; for (int i = 0; i < input.length(); i++) { char ch = (char) (input.charAt(i) + i + salt); hashed += ch; } return hashed; } // Hash Function 1: Sum of character values (in this scenario hash will not always have the same length as // an input string) public static String hashSum(String input) { int hash = 0; for (char c : input.toCharArray()) { hash += c; } return Integer.toHexString(hash); } // Hash Function 2: XOR of character values - in java ^ is a XOR (exclusive or) operator // it is only true when two compared bits are different e.g. 1 XOR 0 = 1 but 1 XOR 1 = 0 public static String hashXOR(String input) { int hash = 0; for (char c : input.toCharArray()) { hash ^= c; } return Integer.toHexString(hash); } // Hash Function 3: Bit shift with addition public static String hashShift(String input) { int hash = 0; for (char c : input.toCharArray()) { hash = (hash << 5) - hash + c; } return Integer.toHexString(hash); } // Hash Function 4: Multiplication by a constant public static String hashMultiply(String input) { int hash = 1; for (char c : input.toCharArray()) { hash = hash * 31 + c; } return Integer.toHexString(hash); } // Hash Function 5: Simple cyclic sum (modulo division, where % is a modulo operator) public static String hashCyclicSum(String input) { int hash = 0; for (char c : input.toCharArray()) { hash = (hash + c) % 256; } return Integer.toHexString(hash); } }