-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd5Hybrid.java
105 lines (66 loc) · 2.04 KB
/
md5Hybrid.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.krakenj.md5Hybrid;
import java.nio.charset.StandardCharsets;
import java.security.*;
public class md5Hybrid{
void md5Hybrid(){
//code here
}
public static void main(String [] args){
int[] mcode = new int[] {3,5,6,4,1,2,0,7};
String str = md5hybrid("rolly", mcode);
System.out.println(str);
for(int i=0; i<8; i++)System.out.print(mcode[i]);
}//main
public static String md5hybrid(String pass, int[] mcode){
//cound how many digit the mcode
int counter = 0;
for (int i = 0; i < mcode.length; i ++) counter ++;
//hash the passw2ord
String hashedTextPassString = MD5(pass);
//convert md5 hash string into char array
char[] hashedTextPassCharArr;
hashedTextPassCharArr = hashedTextPassString.toCharArray();
//CALCULATE CHUNCK LENGTH
int chunkLenght = 32/(counter-1);
System.out.println("chunkLenght = " + chunkLenght);
//INSERT COMMA BETWEEN CHUNKS
int l, n = 0;
String strArr = "";
for(l=0;l < 32;l++){
++n;
strArr += hashedTextPassCharArr[l];
if(n == chunkLenght) { strArr += ","; n = 0;}
}//
//separate delimited string
String[] output = strArr.split(",");
//count how many index in the array
int index_count = 0;
for (int i = 0; i < output.length; i++)
if (output[i] != null) index_count++;
//SCRAMBLER!
int j,i;
String scrambledEgg = "";
for(j = 0; j != 8; j++){
for(i = 0; i != (8+1); i++){
if(mcode[j] == i){
scrambledEgg += output[i] + " ";
}
}
}//for j;
/******************************/
return scrambledEgg;
}
public static String MD5(String md5) {
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
}
return null;
}
}