예제 #1
0
        public byte[] DecryptStream(Stream stream, int length, int iv)
        {
            var buff = new byte[length];

            if (!Decrypt)
            {
                stream.Read(buff, 0, length);
                return(buff);
            }

            var plaintext = new byte[length];

            using (var aesAlg = new Aes128CounterMode(NollaPrng.Get16Seeded(iv))) {
                // Create a decryptor to perform the stream transform.
                var decryptor = aesAlg.CreateDecryptor(AESKey, null);
                var buffer    = new byte[length];
                stream.Read(buffer, 0, length);
                using (MemoryStream limitedStream = new MemoryStream(buffer)) {
                    using (CryptoStream csDecrypt = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read)) {
                        csDecrypt.Read(plaintext, 0, length);
                    }
                }
            }
            return(plaintext);
        }
예제 #2
0
 public static void DoMain(string[] args)
 {
     foreach (var arg in args)
     {
         if (uint.TryParse(arg, out var value))
         {
             var prng = new NollaPrng(value);
             Console.WriteLine($"Next state for seed {value}: {prng.Seed}, error on float cast {prng.Seed - ((double)(float)(prng.Seed * ((double)1 / int.MaxValue))) * (0x8000_0000)}");
             Console.WriteLine($"IV bytes for given seed are: {BitConverter.ToString(Get16Seeded((int)value))}");
         }
     }
 }
예제 #3
0
        public static byte[] Get16Seeded(int seed, int seedBase = SEED_BASE)
        {
            var prng = new NollaPrng(seed, seedBase);

            return(prng.Next16());
        }