MD5 Hash Brute Force java -
i having trouble creating brute force java code class assignment. professor not hoping lend me hand or give tips. professor supplied 2 methods md5_bytes
, mini_md5_bytes
. mini bytes used decode 24 bits instead of full hash. have tried go on own , have hit wall. random string generator attempt @ trying use random strings find hash preselected word s. appreciate help.
public class bruteforce { static int num_bytes=24; static string rand = ""; static string s = "aefbcefacefeacaecefc"; static byte[] random = null; static byte[] md = null; public static void main(string[] args) throws exception{ md = mini_md5_bytes(s, num_bytes); if(s.equalsignorecase(rand)){ system.out.println(rand); } else{ rand = brute(md, s); } } public static byte[] mini_md5_bytes(string s, int num_bytes){ byte[] md = md5_bytes(s); return arrays.copyof(md,num_bytes); } public static byte[] md5_bytes(string s){ messagedigest md; try { md = messagedigest.getinstance("md5"); md.update(s.getbytes()); return md.digest(); } catch( java.security.nosuchalgorithmexception e) { return null; } } public static string brute(byte[] md, string s) throws exception{ while(!s.equalsignorecase(rand)){ rand = randomstringgenerator.generaterandomstring(20,randomstringgenerator.mode.alpha); byte[] random = mini_md5_bytes(rand, num_bytes); if((arrays.equals(random, md))){ rand = s; return rand; } } return null; } }
whilst md5 no longer considered safe crypto, not imply md5 easy brute force.
as others have suggested in comments, don't try random strings (especially because generation of random numbers slow). brute force trying combinations until match found.
also, reading mini_md5_bytes()
seems don't want find 2 strings same md5 hash, same md5 "prefix".
if that's case, use small number num_bytes
. maybe start 1 or 2 , increase number until tool becomes slow. way, note you're using num_bytes=24
, i.e. 192 bits, while md5 produces 128 bits.
also, why using s.equalsignorecase(rand)
? if want brute force md5 hash, should not care input string s
. string should not input! if s
input, use rand = s
, done. aim find hash collision, not find original string.
this correct signature brute()
function:
public static string brute(byte[] md) throws exception
and correct condition while
-loop:
while(!arrays.equals(random, md))
Comments
Post a Comment