本帖最后由 Enigma_G 于 2017-5-2 22:40 编辑
0x00 闲言碎语
这位朋友 @挥汗如雨 说让我写第四题,他写第五题 ,看了下题挺简单就答应了。。。我就简单分析下这题
题目链接 http://pan.baidu.com/s/1sljl0vz
0x01 解题
[Java] 纯文本查看 复制代码 public static void main(final String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
final CheckInterface checkerObject = loadCheckerObject();
final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Enter password:");
final String line = stdin.readLine();
if (checkerObject.checkPassword(line)) {
System.out.println("Well done, that is the correct password");
System.exit(0);
}
else {
System.out.println("Incorrect password");
}
}
调用了checkPassword
[Java] 纯文本查看 复制代码 public boolean checkPassword(final String input) {
MessageDigest md5Obj = null;
try {
md5Obj = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
System.out.println("Hash Algorithm not supported");
System.exit(-1);
}
byte[] hashBytes = new byte[40];
md5Obj.update(input.getBytes(), 0, input.length());
hashBytes = md5Obj.digest();
return byteArrayToHexString(hashBytes).equals("fa3733c647dca53a66cf8df953c2d539");
}
那么就把“fa3733c647dca53a66cf8df953c2d539"MD5解密一下
好啦,看好执行的逻辑,这道题就是秒破
0x02 结语
好了,继续看书,下面开始你的表演 @挥汗如雨
|