I don't want to calculate a file's checksum, just to know if a given string is a valid checksum
+8
A:
Any 160-bit sequence is a possible SHA1 hash. Any 128-bit sequence is a possible MD5 hash.
If you're looking at the hex string representations of them, then a sha1 will look like 40 hexadecimal digits, and an md5 will look like 32 hexadecimal digits.
Jonathan Feinberg
2009-12-13 14:47:20
so check for a 40 digit and 32 digit hex number respectively
cobbal
2009-12-13 14:48:35
Ha; you added your comment while I was editing. +1
Jonathan Feinberg
2009-12-13 14:50:40
+6
A:
SHA1 verifier:
public boolean isValidSHA1(String s) {
return s.matches("[a-fA-F0-9]{40}");
}
MD5 verifier:
public boolean isValidMD5(String s) {
return s.matches("[a-fA-F0-9]{32}");
}
dfa
2009-12-13 14:55:07
Is it strange and wonderful that dfa should provide a couple of DFAs?
Jonathan Feinberg
2009-12-13 15:18:59