0

I am new at Java programming. So i need your help.

how can i decrypt a String.hashcode() to string again? Brute forcing?

public class flag {

public static boolean isFlag(String str) {
    return str.hashCode() == 1471587914 && str.toLowerCase().hashCode() == 1472541258;
}

public static void main(String[] args) {
    int a = 1471587914;
    String flag = "------";

    if (isFlag(flag))
        System.out.println("You found it!");
    else
        System.out.println("Try again :(");

}

}

Atilla
  • 59
  • 1
  • 6
  • 2
    The entire point of a hash is that it's one-way. It can't be undone. And it's possible for the same hash to come from different strings, so brute force methods may not produce a consistent result. – TFrazee Jun 06 '18 at 18:39
  • Why would you do that? – MC Emperor Jun 06 '18 at 18:41
  • According to [the specification of hashCode](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) "It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results." – Jonathan Rosenne Jun 06 '18 at 18:56
  • @TFrazee Actually, nothing in [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode()) says that *the entire point of a hash is that it's one-way*. There's no requirement for irreversibility of the hash. So it's not *the entire point*. – lexicore Jun 06 '18 at 19:39

0 Answers0