internal class HashAnalyze
{
Dictionary<string, string> _hashTypes = new Dictionary<string, string>()
{
{ "SHA-256", "^[a-fA-F0-9]{64}$" },
{ "SHA-512", "^[a-fA-F0-9]{128}$" },
{ "SHA-3", "^[a-fA-F0-9]{64}$" },
{ "SHA-1", "^[a-fA-F0-9]{40}$" },
{ "MD5", "^[a-fA-F0-9]{32}$" },
{ "BLAKE2", "^[a-fA-F0-9]{64}$" },
{ "Whirlpool", "^[a-fA-F0-9]{128}$" },
{ "RIPEMD-160", "^[a-fA-F0-9]{40}$" },
{ "Tiger", "^[a-fA-F0-9]{64}$" },
{ "Keccak", "^[a-fA-F0-9]{64}$" },
{ "CRC32", "^[a-fA-F0-9]{8}$" },
{ "SHA-384", "^[a-fA-F0-9]{96}$" },
{ "SHA-224", "^[a-fA-F0-9]{56}$" },
{ "SHA-512/256", "^[a-fA-F0-9]{64}$" },
{ "SHA-512/224", "^[a-fA-F0-9]{56}$" },
{ "SHA-3-256", "^[a-fA-F0-9]{64}$" },
{ "SHA-3-512", "^[a-fA-F0-9]{128}$" },
{ "Skein-512", "^[a-fA-F0-9]{128}$" },
{ "Skein-256", "^[a-fA-F0-9]{64}$" },
{ "Grøstl-512", "^[a-fA-F0-9]{128}$" },
{ "Grøstl-256", "^[a-fA-F0-9]{64}$" },
{ "HAS-160", "^[a-fA-F0-9]{40}$" },
{ "HAS-256", "^[a-fA-F0-9]{64}$" },
{ "HAS-512", "^[a-fA-F0-9]{128}$" },
{ "ECOH-512", "^[a-fA-F0-9]{128}$" },
{ "ECOH-256", "^[a-fA-F0-9]{64}$" },
{ "MD4", "^[a-fA-F0-9]{32}$" },
{ "SM3", "^[a-fA-F0-9]{64}$" },
{ "BLAKE3", "^[a-fA-F0-9]{64}$" },
{ "SWIFFT-512", "^[a-fA-F0-9]{128}$" },
};
private int _maxLengthToAlignment;
private string _hash = String.Empty;
public HashAnalyze()
{
_maxLengthToAlignment = _hashTypes.Keys.Max(key => key.Length) + 2;
}
public void Check(string hash)
{
_hash = hash;
foreach (string name in _hashTypes.Keys)
{
CheckHashMatch(name, _hashTypes[name]);
}
}
private void CheckHashMatch(string hashName, string hashRegexPatern)
{
Match match = Regex.Match(_hash, hashRegexPatern);
WriteConsole(hashName, match.Success);
}
private void WriteConsole(string hashName, bool isMatch)
{
string matchString = isMatch ? "+" : "-";
Console.ForegroundColor = isMatch ? ConsoleColor.Green : ConsoleColor.Red;
Console.WriteLine($"{hashName}{new string(' ',_maxLengthToAlignment - hashName.Length)}[{matchString}]");
Console.ForegroundColor = ConsoleColor.White;
}
}