Skip to content

Commit 0a33f04

Browse files
committed
Test with both UTF-8 and ASCII encoding (I tested with Jörg/jörg/Jürg/jürg/Müller/müller, which are all found now)
1 parent 29dc36b commit 0a33f04

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/main/java/org/fastfilter/tools/PasswordLookup.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ public static void main(String... args) throws Exception {
4545
}
4646

4747
private static void testPassword(String filterFile, long[] segmentStarts, String password) throws Exception {
48-
// it's unclear which character set was used; ASCII gave good results, as
49-
// umlauts are converted to '?'
50-
byte[] passwordBytes = password.getBytes(Charset.forName("ASCII"));
48+
Result utf8 = testPassword(filterFile, segmentStarts, password, "UTF-8");
49+
Result ascii = testPassword(filterFile, segmentStarts, password, "ASCII");
50+
Result max = utf8.compareTo(ascii) >= 0 ? utf8 : ascii;
51+
System.out.println(max);
52+
}
53+
54+
private static Result testPassword(String filterFile, long[] segmentStarts, String password, String charset) throws Exception {
55+
byte[] passwordBytes = password.getBytes(Charset.forName(charset));
5156
MessageDigest md = MessageDigest.getInstance("SHA-1");
5257
byte[] sha1 = md.digest(passwordBytes);
5358
long hash = 0;
@@ -61,11 +66,24 @@ private static void testPassword(String filterFile, long[] segmentStarts, String
6166
XorPlus8 filter = new XorPlus8(in);
6267
in.close();
6368
if (filter.mayContain(key)) {
64-
System.out.println("Found");
69+
return Result.FOUND;
6570
} else if (filter.mayContain(key | 1)) {
66-
System.out.println("Found; common");
71+
return Result.FOUND_COMMON;
6772
} else {
68-
System.out.println("Not found");
73+
return Result.NOT_FOUND;
74+
}
75+
}
76+
77+
static enum Result {
78+
NOT_FOUND("Not found"),
79+
FOUND("Found"),
80+
FOUND_COMMON("Found; common");
81+
private final String message;
82+
Result(String message) {
83+
this.message = message;
84+
}
85+
public String toString() {
86+
return message;
6987
}
7088
}
7189

0 commit comments

Comments
 (0)