public static BigInteger RandomPrimeBigInteger(BigInteger maxValue) { RandomNumberGenerator rng = RandomNumberGenerator.Create(); byte[] bytes = new byte[maxValue.ToByteArray().LongLength]; BigInteger result; do { do { rng.GetBytes(bytes); result = BigInteger.Abs(new BigInteger(bytes)); } while (result > maxValue); } while (!DiffieHellman.IsProbablePrime(result, MILLER_RABIN_CERTAINTY)); return(result); }
static void Main(string[] args) { IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); // получаем адреса для запуска сокета Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // создаем сокет try { listenSocket.Bind(ipPoint); //связываем сокет с локальной точкой, по которой будем принимать данные listenSocket.Listen(10); //начинаем прослушивание Console.WriteLine("Server is on. Waiting for connection..."); while (true) { Socket handler = listenSocket.Accept(); BinaryReader br = new BinaryReader(new NetworkStream(handler)); byte OPERATION_CODE = br.ReadByte(); if (OPERATION_CODE == REGISTRATION_CODE) { String login = br.ReadString(); String hashPassword = br.ReadString(); String output = "Connection: Code of operation: " + OPERATION_CODE + "; login: "******"Connection: Code of operation: " + OPERATION_CODE + "; login: "******"User " + login + " has send a message:"); Console.WriteLine(message); handler.Send(new byte[] { answer }); bw.Write(answer); handler.Shutdown(SocketShutdown.Both); handler.Close(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }