using System.Security.Cryptography;
public interface IMD5Info
void CountMD5(Stream stream);
public interface ISHA1Info
void CountSHA1(Stream stream);
public class RutrackerHashInfo : IMD5Info, ISHA1Info
private bool isMd5Counted = false;
private bool isSha1Counted = false;
public string Path {get; set;}
public string Error {get; private set;}
public void CountMD5(Stream stream)
MD5 md5csp = new MD5CryptoServiceProvider();
md5 = BitConverter.ToString(md5csp.ComputeHash(stream)).Replace("-", "");
public void CountSHA1(Stream stream)
SHA1 sha1csp = new SHA1CryptoServiceProvider();
sha1 = BitConverter.ToString(sha1csp.ComputeHash(stream)).Replace("-", "");
using (FileStream fileStream = File.Open(Path, FileMode.Open))
this.CountMD5(fileStream);
this.CountSHA1(fileStream);
public RutrackerHashInfo()
public class RutrackerHashThreaded
private static void OutputHash(RutrackerHashInfo hashInfo)
Console.WriteLine(hashInfo.Path);
if (hashInfo.Error != null)
Console.WriteLine("Error counting hash: {0}", hashInfo.Error);
Console.WriteLine("MD5 : {0}", hashInfo.MD5);
if (hashInfo.SHA1Counted)
Console.WriteLine("SHA-1: {0}", hashInfo.SHA1);
public static void Main(string[] args)
if ((args == null) || (args.Length < 1))
directory = Directory.GetCurrentDirectory();
if (Directory.Exists(directory))
string[] filenames = Directory.GetFiles(directory);
RutrackerHashInfo hashInfo;
foreach (string filename in filenames)
hashInfo = new RutrackerHashInfo();
hashInfo.Path = filename;
Console.WriteLine("Directory {0} doesn't exist", directory);