using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Sha1Sum
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 1) {
                Log("I need the filename as parm.");
                return;
            }

            var filename = args[0];

            StringBuilder formatted;

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            using (BufferedStream bs = new BufferedStream(fs))
            {
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    byte[] hash = sha1.ComputeHash(bs);
                    formatted = new StringBuilder(2 * hash.Length);
                    foreach (byte b in hash)
                    {
                        formatted.AppendFormat("{0:X2}", b);
                    }
                }
            }

            Log(formatted.ToString());
        }

        private static void Log(string p)
        {
            Console.WriteLine(p + Environment.NewLine);
        }
    }
}