Ejemplo n.º 1
0
        private static void ComputeMd5Hash()
        {
            var image      = File.ReadAllBytes("Files/image.jpg");
            var sourceCode = File.ReadAllBytes("Files/SourceCode.cs");
            var wordDoc    = File.ReadAllBytes("Files/word_doc.docx");

            var imageHash   = HashUtil.Md5Hash(image);
            var sourceHash  = HashUtil.Md5Hash(sourceCode);
            var wordDocHash = HashUtil.Md5Hash(wordDoc);

            Console.WriteLine($"image -> {imageHash}");
            Console.WriteLine($"source -> {sourceHash}");
            Console.WriteLine($"doc file -> {wordDocHash}");
        }
Ejemplo n.º 2
0
        public static CollisionResult FindCollision(string hash, int bitLength)
        {
            for (long i = 0; i < long.MaxValue; i++)
            {
                var byteContent = BitConverter.GetBytes(i);
                var testHash    = HashUtil.GetHash(byteContent, bitLength);

                if (testHash == hash)
                {
                    var text = Convert.ToBase64String(byteContent);

                    return(new CollisionResult(text, i + 1));
                }
            }

            return(new CollisionResult());
        }
Ejemplo n.º 3
0
        private static void ComputeStringHash()
        {
            while (true)
            {
                Console.WriteLine("Input text:");
                var text = Console.ReadLine();

                if (text.Trim() == "exit")
                {
                    break;
                }

                Console.WriteLine("Input bit length (2, 4, 8):");
                var bitLength = Console.ReadLine();

                var hash = HashUtil.GetHash(Encoding.UTF8.GetBytes(text), int.Parse(bitLength));

                Console.WriteLine($"Hash: {hash}");
            }
        }