import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
class Ideone {
/** 解析したいMD5ハッシュ */
private static final byte[] TARGET = decodeHex("ab56b4d92b40713acc5af89985d4b786");
/** ループ回数 */
private static final long CHALLENGE_MAX
= Long.
parseLong("zzzzzz",
Character.
MAX_RADIX);
public static void main
(String[] args
) {
for (long i = 0; i < CHALLENGE_MAX; i++) {
byte[] digest = getDigest().digest(challenge.getBytes());
if (Arrays.
equals(TARGET, digest
)) { System.
out.
println("答えは " + challenge
); break;
}
if (i % 1000000 == 0) {
System.
out.
println(i
+ "回目の試行..." + challenge
); }
}
}
/**
* メッセージダイジェストのインスタンスを取得
*
* @param algorithm アルゴリズム
* @return
*/
if (digest != null) {
return digest;
}
try {
}
}
/**
* 16進数文字列をバイト配列にする
*
* @param str
* @return
*/
public static byte[] decodeHex
(String str
) { final char[] data = str.toCharArray();
final int len = data.length;
final byte[] out = new byte[len >> 1];
// two characters form the hex value.
for (int i = 0, j = 0; j < len; i++) {
j++;
j++;
out[i] = (byte) (f & 0xFF);
}
return out;
}
}
aW1wb3J0IGphdmEuc2VjdXJpdHkuTWVzc2FnZURpZ2VzdDsKaW1wb3J0IGphdmEuc2VjdXJpdHkuTm9TdWNoQWxnb3JpdGhtRXhjZXB0aW9uOwppbXBvcnQgamF2YS51dGlsLkFycmF5czsKCmNsYXNzIElkZW9uZSB7CgogICAgLyoqIOino+aekOOBl+OBn+OBhE1ENeODj+ODg+OCt+ODpSAqLwogICAgcHJpdmF0ZSBzdGF0aWMgZmluYWwgYnl0ZVtdIFRBUkdFVCA9IGRlY29kZUhleCgiYWI1NmI0ZDkyYjQwNzEzYWNjNWFmODk5ODVkNGI3ODYiKTsKCiAgICAvKiog44Or44O844OX5Zue5pWwICovCiAgICBwcml2YXRlIHN0YXRpYyBmaW5hbCBsb25nIENIQUxMRU5HRV9NQVggPSBMb25nLnBhcnNlTG9uZygienp6enp6IiwgQ2hhcmFjdGVyLk1BWF9SQURJWCk7CgogICAgcHJpdmF0ZSBzdGF0aWMgTWVzc2FnZURpZ2VzdCBkaWdlc3Q7CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewoKICAgICAgICBTdHJpbmcgY2hhbGxlbmdlOwogICAgICAgIGZvciAobG9uZyBpID0gMDsgaSA8IENIQUxMRU5HRV9NQVg7IGkrKykgewogICAgICAgICAgICBjaGFsbGVuZ2UgPSBMb25nLnRvU3RyaW5nKGksIENoYXJhY3Rlci5NQVhfUkFESVgpOwogICAgICAgICAgICBieXRlW10gZGlnZXN0ID0gZ2V0RGlnZXN0KCkuZGlnZXN0KGNoYWxsZW5nZS5nZXRCeXRlcygpKTsKCiAgICAgICAgICAgIGlmIChBcnJheXMuZXF1YWxzKFRBUkdFVCwgZGlnZXN0KSkgewogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCLjgoTjgorjgb7jgZfjgZ8iKTsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigi562U44GI44GvICIgKyBjaGFsbGVuZ2UpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGkgJSAxMDAwMDAwID09IDApIHsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihpICsgIuWbnuebruOBruippuihjC4uLiIgKyBjaGFsbGVuZ2UpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIC8qKgogICAgICog44Oh44OD44K744O844K444OA44Kk44K444Kn44K544OI44Gu44Kk44Oz44K544K/44Oz44K544KS5Y+W5b6XCiAgICAgKiAKICAgICAqIEBwYXJhbSBhbGdvcml0aG0g44Ki44Or44K044Oq44K644OgCiAgICAgKiBAcmV0dXJuCiAgICAgKi8KICAgIHByaXZhdGUgc3RhdGljIE1lc3NhZ2VEaWdlc3QgZ2V0RGlnZXN0KCkgewogICAgICAgIGlmIChkaWdlc3QgIT0gbnVsbCkgewogICAgICAgICAgICByZXR1cm4gZGlnZXN0OwogICAgICAgIH0KICAgICAgICB0cnkgewogICAgICAgICAgICByZXR1cm4gZGlnZXN0ID0gTWVzc2FnZURpZ2VzdC5nZXRJbnN0YW5jZSgiTUQ1Iik7CiAgICAgICAgfSBjYXRjaCAoTm9TdWNoQWxnb3JpdGhtRXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFJ1bnRpbWVFeGNlcHRpb24oZS5nZXRNZXNzYWdlKCkpOwogICAgICAgIH0KICAgIH0KCiAgICAvKioKICAgICAqIDE26YCy5pWw5paH5a2X5YiX44KS44OQ44Kk44OI6YWN5YiX44Gr44GZ44KLCiAgICAgKiAKICAgICAqIEBwYXJhbSBzdHIKICAgICAqIEByZXR1cm4KICAgICAqLwogICAgcHVibGljIHN0YXRpYyBieXRlW10gZGVjb2RlSGV4KFN0cmluZyBzdHIpIHsKICAgICAgICBmaW5hbCBjaGFyW10gZGF0YSA9IHN0ci50b0NoYXJBcnJheSgpOwogICAgICAgIGZpbmFsIGludCBsZW4gPSBkYXRhLmxlbmd0aDsKICAgICAgICBmaW5hbCBieXRlW10gb3V0ID0gbmV3IGJ5dGVbbGVuID4+IDFdOwogICAgICAgIC8vIHR3byBjaGFyYWN0ZXJzIGZvcm0gdGhlIGhleCB2YWx1ZS4KICAgICAgICBmb3IgKGludCBpID0gMCwgaiA9IDA7IGogPCBsZW47IGkrKykgewogICAgICAgICAgICBpbnQgZiA9IENoYXJhY3Rlci5kaWdpdChkYXRhW2pdLCAxNikgPDwgNDsKICAgICAgICAgICAgaisrOwogICAgICAgICAgICBmID0gZiB8IENoYXJhY3Rlci5kaWdpdChkYXRhW2pdLCAxNik7CiAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgb3V0W2ldID0gKGJ5dGUpIChmICYgMHhGRik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBvdXQ7CiAgICB9Cn0K