Untitled

mail@pastecode.io avatar
unknown
java
a year ago
1.3 kB
6
Indexable
Never
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static void main(String[] args) {
        String targetHash = "da94176722ff612f89b9e75e4bc96b19";
        String characters = "0123456789abcdefghijklmnopqrstuvwxyz";

        for (char c1 : characters.toCharArray()) {
            for (char c2 : characters.toCharArray()) {
                String attempt = "4011414105" + c1 + c2 + "07";
                String hash = md5Hash(attempt);
                assert hash != null;
                if (hash.equals(targetHash)) {
                    System.out.println("hash shoma barabar ast ba: " + attempt);
                    return;
                }
            }
        }

        System.out.println("hash peyda nashod.");
    }
    
    public static String md5Hash(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = md.digest(input.getBytes());

            StringBuilder result = new StringBuilder();
            for (byte b : bytes) {
                result.append(String.format("%02x", b));
            }

            return result.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
}