Esempio n. 1
0
        public static double[] Compute(this BasicNetwork network, double[] input)
        {
            double[] retVal = new double[network.OutputCount];

            network.Compute(input, retVal);

            return retVal;
        }
 /// <summary>
 /// Computes the Gray-level Run-length for the given image source.
 /// </summary>
 /// <param name="grayLevelRunLengthMatrix">Gray-Level Run-Length Matrix.</param>
 /// <param name="source">The source image.</param>
 /// <returns>An array of run-length vectors containing level counts for every width pixel in <paramref name="source"/>.</returns>
 public static double[][] Compute(this GrayLevelRunLengthMatrix grayLevelRunLengthMatrix, Image<Gray<byte>> source)
 {
     return grayLevelRunLengthMatrix.Compute(source.AsAForgeImage());
 }
 /// <summary>
 /// Computes the Gray-level Run-length for the given image source.
 /// </summary>
 /// <param name="grayLevelRunLengthMatrix">Gray-Level Run-Length Matrix.</param>
 /// <param name="source">The source image.</param>
 /// <returns>An array of run-length vectors containing level counts for every width pixel in <paramref name="source"/>.</returns>
 public static double[][] Compute(this GrayLevelRunLengthMatrix grayLevelRunLengthMatrix, Image<Gray, byte> source)
 {
     return grayLevelRunLengthMatrix.Compute(source.ToAForgeImage(copyAlways: false, failIfCannotCast: true));
 }
Esempio n. 4
0
        public static byte[] MakePbkdf2(this IKeyedHashFunction hash, byte[] data, byte[] salt, int length, int iterationCount)
        {
            hash.Key = data;

            int hashLength = hash.HashSize/8;
            if ((hash.HashSize & 7) != 0)
                hashLength++;

            int keyLength = length/hashLength;
            if (length > (0xFFFFFFFFL*hashLength) || length < 0)
                throw new ArgumentOutOfRangeException("length");

            if (length%hashLength != 0)
                keyLength++;

            byte[] extendedkey = new byte[salt.Length + 4];
            Buffer.BlockCopy(salt, 0, extendedkey, 0, salt.Length);

            using (var ms = new MemoryStream()) {
                for (int i = 0; i < keyLength; i++) {
                    extendedkey[salt.Length] = (byte) (((i + 1) >> 24) & 0xFF);
                    extendedkey[salt.Length + 1] = (byte) (((i + 1) >> 16) & 0xFF);
                    extendedkey[salt.Length + 2] = (byte) (((i + 1) >> 8) & 0xFF);
                    extendedkey[salt.Length + 3] = (byte) (((i + 1)) & 0xFF);

                    byte[] u = hash.Compute(extendedkey);
                    Array.Clear(extendedkey, salt.Length, 4);

                    byte[] f = u;
                    for (int j = 1; j < iterationCount; j++) {
                        u = hash.Compute(u);
                        for (int k = 0; k < f.Length; k++) {
                            f[k] ^= u[k];
                        }
                    }

                    ms.Write(f, 0, f.Length);
                    Array.Clear(u, 0, u.Length);
                    Array.Clear(f, 0, f.Length);
                }

                byte[] dk = new byte[length];
                ms.Position = 0;
                ms.Read(dk, 0, length);
                ms.Position = 0;

                for (long i = 0; i < ms.Length; i++) {
                    ms.WriteByte(0);
                }

                Array.Clear(extendedkey, 0, extendedkey.Length);
                return dk;
            }
        }
Esempio n. 5
0
 public static string ComputeString(this IHashFunction hash, string s)
 {
     var data = Encoding.UTF8.GetBytes(s);
     return BinaryToHex(hash.Compute(data));
 }