예제 #1
0
파일: Program.cs 프로젝트: alipha/xhash
        private static void VisitCounts()
        {
            var chars = "0123456789abcdefghijklmnopqrstuvwxyz".ToCharArray();

            var hasher = new TestPasswordHasher("Qq48KGoFOXbZcBXDHZuqyjTP5oBfUy4N2iEHmL2NkIw=", 12288, 4);

            DateTime startTime = DateTime.UtcNow;
            hasher.Hash("foo", "");
            Console.WriteLine((DateTime.UtcNow - startTime).TotalMilliseconds);

            System.IO.File.WriteAllText(@"stats\hash-12288-16.txt", String.Join("", hasher._visitCounts.Select(v => chars[v])));
        }
예제 #2
0
파일: Program.cs 프로젝트: alipha/xhash
        public static void Main(string[] args)
        {
            /*
            string user_salt = "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp";
            string password = "******";
            var pbkdf2 = new PBKDF2<HMACSHA512>(Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(user_salt), 50);
            var bytes = pbkdf2.GetBytes(128);

            Console.WriteLine(String.Join("", bytes.Select(x => x.ToString("X2"))));
            return;
             */

            Console.WriteLine(PasswordHasher.GenerateSalt());

            int iterations = 0;
            int memoryBits = 22;

            var chasher = new PasswordHasher("Qq48KGoFOXbZcBXDHZuqyjTP5oBfUy4N2iEHmL2NkIw=", memoryBits, iterations);

            var startTime = DateTime.UtcNow;
            string hash = chasher.Hash("foo1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");
            Console.WriteLine((DateTime.UtcNow - startTime).TotalMilliseconds);
            Console.WriteLine(hash);
            Console.WriteLine(chasher.MemoryUsage);

            var hasher = new TestPasswordHasher("Qq48KGoFOXbZcBXDHZuqyjTP5oBfUy4N2iEHmL2NkIw=", memoryBits, iterations);

            startTime = DateTime.UtcNow;
            hash = hasher.Hash("foo1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");
            Console.WriteLine((DateTime.UtcNow - startTime).TotalMilliseconds);
            Console.WriteLine(hash);
            Console.WriteLine(hasher.MemoryUsage);
            #if DEBUG
            /* cell frequency */
            if (!Directory.Exists("stats"))
                Directory.CreateDirectory("stats");

            CellFrequency(String.Format("cellfreq-{0}-{1}.txt", memoryBits, iterations), hasher.__hashArray);

            /* xored cell frequency */
            byte[] xored = new byte[hasher.MemoryUsage];

            for (int i = 0; i < xored.Length; i++)
                xored[i] = (byte)(hasher.__hashArray[i] ^ hasher._originalArray[i]);

            Console.WriteLine("0 xor bytes: " + xored.Count(x => x == 0));

            CellFrequency(String.Format("xor-cellfreq-{0}-{1}.txt", memoryBits, iterations), xored);

            /* visit counts */
            var chars = "0123456789abcdefghijklmnopqrstuvwxyz".ToCharArray();
            System.IO.File.WriteAllText(String.Format(@"stats\hash-{0}-{1}.txt", memoryBits, iterations), String.Join("", hasher._visitCounts.Select(v => chars[v])));

            /* depth, count, iterations */
            _mixingHashes = hasher._hashes.Skip(1);

            string prevHash = hasher._hashes[0];

            _info[prevHash] = new HashTreeInfo
            {
                depth = 1,
                count = 0,
                iterations = 1
            };

            foreach(string nextHash in _mixingHashes)
            {
                _prevHash[nextHash] = prevHash;
                prevHash = nextHash;
            }

            var depths = _mixingHashes.Select(h => GetTreeInfo(hasher, h).ToString());
            System.IO.File.WriteAllLines(String.Format(@"stats\depths-{0}-{1}.txt", memoryBits, iterations), depths);
            #endif
            Console.ReadLine();
        }
예제 #3
0
파일: Program.cs 프로젝트: alipha/xhash
        private static void Test()
        {
            var hasher1 = new TestPasswordHasher("Qq48KGoFOXbZcBXDHZuqyjTP5oBfUy4N2iEHmL2NkIw=");
            var hasher2 = new TestPasswordHasher("Qq48KGoFOXbZcBXDHZuqyjTP5oafUy4N2iEHmL2NkIw=");
            var hasher3 = new TestPasswordHasher("Qq48KGoFOXbZcBXDHZuqyjTP5oBfUy4N2iEHmL2NkIw=", 17001);
            //Console.WriteLine(PasswordHasher.GenerateSalt());

            var startTime = DateTime.UtcNow;
            var result1a = hasher1.Hash("password1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");
            Console.WriteLine((DateTime.UtcNow - startTime).TotalMilliseconds);

            var result1b = hasher1.Hash("password1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");
            var result1c = hasher1.Hash("password1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCq");
            var result1d = hasher1.Hash("password2", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");
            var result2  = hasher2.Hash("password1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");
            var result3  = hasher3.Hash("password1", "NyfLZ6RJXWE1aHrrM5JRefMlipdBV0bCp");

            Console.WriteLine(result1a);
            Console.WriteLine(result1b);
            Console.WriteLine();
            Console.WriteLine(result1a);
            Console.WriteLine(result1c);
            Console.WriteLine();
            Console.WriteLine(result1a);
            Console.WriteLine(result1d);
            Console.WriteLine();
            Console.WriteLine(result1a);
            Console.WriteLine(result2);
            Console.WriteLine();
            Console.WriteLine(result1a);
            Console.WriteLine(result3);
            Console.WriteLine();
        }