Created
September 3, 2012 13:17
-
-
Save ndeverge/3609279 to your computer and use it in GitHub Desktop.
Toulouse Jug Context
This file contains hidden or 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 org.ekito.toulousejugcontest; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.io.UnsupportedEncodingException; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class Main { | |
private final String HASH = "7d60937284c7e9d2954ae777660029b6"; | |
public Main() throws Exception { | |
BufferedReader br = new BufferedReader(new InputStreamReader(getClass() | |
.getResourceAsStream("/dictionary.txt"))); | |
Pattern p = Pattern.compile("[A-Z][a-z]+"); | |
String sCurrentLine; | |
while ((sCurrentLine = br.readLine()) != null) { | |
Matcher match = p.matcher(sCurrentLine.trim()); | |
if (match.matches()) { | |
for (char major = '0'; major <= '9'; major++) { | |
for (char minor = '0'; minor <= '9'; minor++) { | |
String version = String.valueOf(major) + "." | |
+ String.valueOf(minor); | |
String toTest = match.group() + version + "\r\n"; | |
String hashString = MD5(toTest); | |
if (HASH.equals(hashString.trim())) { | |
System.out.println("Here it is !! >> " + toTest); | |
return; | |
} | |
} | |
} | |
} | |
} | |
} | |
private static String convertedToHex(final byte[] data) { | |
StringBuffer buf = new StringBuffer(); | |
for (byte element : data) { | |
int halfOfByte = (element >>> 4) & 0x0F; | |
int twoHalfBytes = 0; | |
do { | |
if ((0 <= halfOfByte) && (halfOfByte <= 9)) { | |
buf.append((char) ('0' + halfOfByte)); | |
} | |
else { | |
buf.append((char) ('a' + (halfOfByte - 10))); | |
} | |
halfOfByte = element & 0x0F; | |
} while (twoHalfBytes++ < 1); | |
} | |
return buf.toString(); | |
} | |
private static String MD5(final String text) | |
throws NoSuchAlgorithmException, UnsupportedEncodingException { | |
MessageDigest md = MessageDigest.getInstance("MD5"); | |
byte[] md5 = new byte[64]; | |
md.update(text.getBytes("UTF-8"), 0, text.length()); | |
md5 = md.digest(); | |
return convertedToHex(md5); | |
} | |
public static void main(final String[] args) { | |
try { | |
new Main(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment