Created
June 18, 2015 04:08
-
-
Save nawada/8bd81249bb6f7e29ee3d to your computer and use it in GitHub Desktop.
数字6桁のMD5ハッシュ値総当り
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import org.apache.commons.codec.digest.DigestUtils; | |
/** | |
* <a href="https://commons.apache.org/proper/commons-codec/">Apache Commons Codec</a>使用 | |
* | |
* http://z.tokumaru.org/2014/02/6php025.html | |
*/ | |
public class CrackHash { | |
public static void main(String[] args) throws Exception { | |
String hashed = "4b364677946ccf79f841114e73ccaf4f"; | |
String salt = "hoge"; | |
CrackHash c = new CrackHash(); | |
long start = System.currentTimeMillis(); | |
for (int i = 0; i < 1000000; i++) { | |
StringBuilder sb = new StringBuilder(); | |
sb.append(salt); | |
sb.append("$"); | |
sb.append(c.filledZero(i, 6)); | |
if (hashed.equals(DigestUtils.md5Hex(sb.toString().getBytes()))) { | |
System.out.println("found: " + sb.toString()); | |
break; | |
} | |
} | |
System.out.println(System.currentTimeMillis() - start); | |
} | |
private String filledZero(int num, int totalLength) { | |
String strNum = String.valueOf(num); | |
int numLen = strNum.length(); | |
if (numLen >= totalLength) { | |
return strNum; | |
} | |
StringBuilder sb = new StringBuilder(); | |
for (int i = numLen; i < totalLength; i++) { | |
sb.append("0"); | |
} | |
sb.append(strNum); | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment