-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
damon
committed
Feb 11, 2022
1 parent
df8f31a
commit 10c4a73
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package iguigui.hash; | ||
|
||
import java.io.*; | ||
|
||
public class HashStringGenerater { | ||
|
||
|
||
//简单生成一大堆具有相同hashCode的字符串 | ||
//输出到文件去 | ||
public static void main(String[] args) { | ||
String[] strings = {"A~", "B_", "C@", "D!"}; | ||
int round = 8; | ||
int pow = (int) Math.pow(4, round); | ||
try { | ||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("hash.json"))); | ||
writer.write("{"); | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
for (int i = 0; i < pow - 1; i++) { | ||
for (int j = round - 1; j >= 0; j--) { | ||
stringBuilder.append(strings[(i / ((int) Math.pow(4, j))) % 4]); | ||
} | ||
writer.write("\""); | ||
writer.write(stringBuilder.toString()); | ||
writer.write("\":0,"); | ||
stringBuilder.delete(0,stringBuilder.length()); | ||
} | ||
for (int j = round - 1; j >= 0; j--) { | ||
stringBuilder.append(strings[(pow / ((int) Math.pow(4, j))) % 4]); | ||
} | ||
writer.write("\""); | ||
writer.write(stringBuilder.toString()); | ||
writer.write("\":0}"); | ||
writer.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package iguigui.hash; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class MyHashTest { | ||
|
||
//一组具有相同hashCode的最小单元 | ||
public static void main(String[] args) { | ||
ArrayList<String> strings = new ArrayList<>(); | ||
strings.add("A~"); | ||
strings.add("B_"); | ||
strings.add("C@"); | ||
strings.add("D!"); | ||
for (String string : strings) { | ||
System.out.println(string + " hashcode = " + string.hashCode()); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package iguigui.hash; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class MyHashTest2 { | ||
|
||
//具有相同hashCode的单元进行简单重复就可以生成一大堆有相同hashCode的字符串 | ||
public static void main(String[] args) { | ||
ArrayList<String> strings = new ArrayList<>(); | ||
strings.add("A~A~A~A~"); | ||
strings.add("A~A~A~B_"); | ||
strings.add("A~A~A~C@"); | ||
strings.add("A~A~A~D!"); | ||
strings.add("A~A~B_A~"); | ||
strings.add("A~A~B_B_"); | ||
strings.add("A~A~B_C@"); | ||
strings.add("A~A~B_D!"); | ||
for (String string : strings) { | ||
System.out.println(string + " hashcode = " + string.hashCode()); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|