Simple hashing function in Java