Beispiel #1
0
        // Test encryption
        static void TestCryptography()
        {
            // Generate a random set of bytes
            byte[] Bytes = SecureRandom.Bytes(32);

            // Write bytes to console
            Console.WriteLine($"Randomly generated bytes: {Encoding.ByteArrayToHexString(Bytes)}");

            var hashes = new Dictionary <IHashProvider, string>
            {
                { new Blake(), "Blake" },
                { new Skein(), "Skein" },
                { new Groestl(), "Groestl" },
                { new JH(), "JH" },
                { new CNV0(), "CNV0" },
                { new CNV1(), "CNV1" },
                { new CNLiteV0(), "CN Lite V0" },
                { new CNLiteV1(), "CN Lite V1" },
            };

            // Hash the bytes with each function
            foreach (var(hashFunction, hashName) in hashes.Tuples())
            {
                Hash(hashFunction, hashName, Bytes);
            }
        }
        public static void HashBenchmark(HashFunction hash, int iterations = 100)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            for (int i = 0; i < iterations; i++)
            {
                byte[] input = SecureRandom.Bytes(64);
                hash.Function.Hash(input);
            }

            stopwatch.Stop();

            TimeSpan ts = stopwatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               ts.Hours, ts.Minutes, ts.Seconds,
                                               ts.Milliseconds / 10);

            Console.WriteLine($"Ran {iterations} iterations of {hash.Name}:");
            Console.WriteLine($"Runtime: {elapsedTime}");
            Console.WriteLine($"Hashes per second: {iterations / ts.TotalSeconds}");
        }
Beispiel #3
0
        public static void HashBenchmark(HashFunction hash)
        {
            var Result = Canti.Benchmark.Run(() => {
                byte[] input = SecureRandom.Bytes(64);
                hash.Function.Hash(input);
            }, hash.Iterations);

            string elapsedTime = Result.ToString(@"hh\:mm\:ss\.ff");

            Console.WriteLine($"Ran {hash.Iterations} iterations of {hash.Name}:");
            Console.WriteLine($"Runtime: {elapsedTime}");
            Console.WriteLine($"Hashes per second: {hash.Iterations / Result.TotalSeconds:F2}");
        }
Beispiel #4
0
        // Test encryption
        static void TestCryptography()
        {
            IHashProvider p;

            // Generate a random set of bytes
            byte[] Bytes = SecureRandom.Bytes(32);

            // Write bytes to console
            Console.WriteLine($"Randomly generated bytes: {Encoding.ByteArrayToHexString(Bytes)}");

            // Keccak the generated bytes
            byte[] KeccakBytes = Keccak.keccak(Bytes);

            // Write keccak bytes to console
            Console.WriteLine($"Keccak: {Encoding.ByteArrayToHexString(KeccakBytes)}");

            // Blake256 the generated bytes
            p = new Blake();
            byte[] BlakeBytes = p.Hash(Bytes);

            // Write blake256 bytes to console
            Console.WriteLine($"Blake: {Encoding.ByteArrayToHexString(BlakeBytes)}");

            // Skein the generated bytes
            p = new Skein();
            byte[] SkeinBytes = p.Hash(Bytes);

            // Write skein bytes to console
            Console.WriteLine($"Skein: {Encoding.ByteArrayToHexString(SkeinBytes)}");

            // Groestl the generated bytes
            p = new Groestl();
            byte[] GroestlBytes = p.Hash(Bytes);

            // Write groestl bytes to console
            Console.WriteLine($"Groestl: {Encoding.ByteArrayToHexString(GroestlBytes)}");

            // JH the generated bytes
            p = new JH();
            byte[] JHBytes = p.Hash(Bytes);

            // Write JH bytes to console
            Console.WriteLine($"JH: {Encoding.ByteArrayToHexString(JHBytes)}");

            // Base58 the generated bytes
            string Base58String = Base58.Encode(Bytes);

            // Write base58 bytes to console
            Console.WriteLine($"Base58: {Base58String}");
            Console.WriteLine();
        }
        // Test encryption
        static void TestCryptography()
        {
            // Generate a random set of bytes
            byte[] Bytes = SecureRandom.Bytes(32);

            // Write bytes to console
            Console.WriteLine($"Randomly generated bytes: {Encoding.ByteArrayToHexString(Bytes)}");

            // Keccak the generated bytes
            byte[] KeccakBytes = Keccak.keccak(Bytes);

            // Write keccak bytes to console
            Console.WriteLine($"Keccak: {Encoding.ByteArrayToHexString(KeccakBytes)}");

            // Base58 the generated bytes
            string Base58String = Base58.Encode(Bytes);

            // Write base58 bytes to console
            Console.WriteLine($"Base58: {Base58String}");
            Console.WriteLine();
        }