Effective ways to find partial sha1 collision I need to find 2 different string and compare their hash value. Both string must contain "abc". I looking for the first eight character that are the same and stop. I have been running for more than 24 hours and still not found. My code has no problem running but i am wondering is there any more effective ways to find the collision

public static void main(String[] args) {
String message1 = "abc";
String message2 = "abc";

int x=0;
if (message1.equals(message2)) {
    String temp1 = message1 + x;
    String temp2 = x + message2;            
    String result1 = sha1Hashing(temp1);
    String result2 = sha1Hashing(temp2);
    while (!result1.equals(result2)){               
        temp1 = message1 + x;
        temp2 = x + message2;               
        result1 = sha1Hashing(temp1);
        result2 = sha1Hashing(temp2);
        System.out.println("First message = " + temp1 + " Second message = " + temp2 + "\n");
        System.out.println("First hash = " + result1);
        System.out.println("Second hash = " + result2 + "\n");
        x++;        
        if(result1.equals(result2)){
            System.out.println("FOUND!!");
            System.exit(0);
        }
    }
}
}
public static String sha1Hashing (String message) {
String sha1 = "";
StringBuffer sb = new StringBuffer();
try {
    MessageDigest mDigest = MessageDigest.getInstance("SHA1");
    byte[] result = mDigest.digest(message.getBytes());

    for (int i = 0; i &lt; result.length; i++) {
        sb.append(Integer.toString((result[i] &amp; 0xff) + 0x100, 16).substring(1));
    }
} catch(NoSuchAlgorithmException e) {
    e.printStackTrace();
}
//return first 8 char
sha1 = sb.toString().substring(0,8);
return sha1;
}
Choosing two strings, hashing them, and comparing the first 8 hex characters of the hash should produce a match once every 2^32 iterations.  The question implies that the values for x for the match aren't required to be the same, so your approach is much too restrictive.  You need to compare the hash you just generated with all of the previous hashes.  If you use a Dictionary&lt;String, String&gt; or similar to store previous results, you can expect a collision after 2^16 elements.

Coding-wise, your byte-to-string conversion can be made more efficient (you do work that is discarded).  You might consider just returning 8 bytes and writing a comparitor for that.