using System; using System.Security.Cryptography; namespace JavaScienceCrypto{ public class Win32 { public class RandomNet { const String title = "RandomNet"; public static void Main() { String[] args = Environment.GetCommandLineArgs(); if(args.Length<2){ Console.WriteLine("Usage: RandomNet [int from 5 to 5000]"); return; } String fname = args[1]; int numbytes=0; try{ numbytes = Int32.Parse(args[1]); } catch(FormatException fexc){ Console.WriteLine("Argument not a valid integer"); return; } catch(Exception exc){ Console.WriteLine("Problem parsing argument {0}\n{1}", args[1], exc); return; } byte[] ranbytes = new byte[numbytes]; RNGCryptoServiceProvider randgen= new RNGCryptoServiceProvider(); randgen.GetBytes(ranbytes); // The array is now filled with cryptographically strong random bytes. Console.WriteLine("------------- Random Bytes[{0}]: ----------------------", numbytes); for(int i=1; i<=ranbytes.Length; i++){ Console.Write("{0:x2} ", ranbytes[i-1]) ; if(i%16 == 0) Console.WriteLine(""); } Console.WriteLine("\n-------------------------------------------------------"); } } } }