private void EavesdropperGoButton_Click(object sender, EventArgs e) { if (_messageSent) { Eavesdropper eavesdropper = new Eavesdropper(); eavesdropper.Break(simulation.client.PublicKey, simulation.client.CoPrime, simulation.server.PublicKey, simulation.server.CoPrime); EavesdropperClientPublicKeyTextBox.Text = simulation.client.PublicKey.ToString(); EavesdropperServerPublicKeyTextBox.Text = simulation.server.PublicKey.ToString(); EavesdropperClientPrivateKeyTextBox.Text = eavesdropper.PrivateKeyClient.ToString(); EavesdropperServerPrivateKeyTextBox.Text = eavesdropper.PrivateKeyServer.ToString(); string message = RSAEncryptor.Decrypt(simulation.server.EncryptedData, simulation.server.PublicKey, eavesdropper.PrivateKeyServer, simulation.server.EncryptedData.Length); EavesdropperMessageTextBox.Text = message; } }
private void StartServer(string ipAddress, int port) { IPAddress ip; ASCIIEncoding ascii = new ASCIIEncoding(); bool res = IPAddress.TryParse(ipAddress, out ip); if (!res) { ip = IPAddress.Loopback; } TcpListener myListener = new TcpListener(ip, port); myListener.Start(); Socket s = myListener.AcceptSocket(); IPEndPoint remoteEndPoint = s.RemoteEndPoint as IPEndPoint; string clientIP = remoteEndPoint.Address.ToString(); Messages[0] = new Message(); Messages[0].Text = _publicKey.ToString() + " " + _coPrimeNumber.ToString(); Messages[0].FromIP = ip.ToString(); Messages[0].ToIP = clientIP + " Client"; s.Send(ascii.GetBytes(_publicKey.ToString())); s.Send(ascii.GetBytes(_coPrimeNumber.ToString())); byte[] b = new byte[10000]; int i = s.Receive(b); byte[] transfer = new byte[i]; for (int k = 0; k < i; k++) { transfer[k] = b[k]; } _encryptedData = transfer; string temp = ""; Byte[] bytes = new Byte[4]; for (int k = 0; k < i; k += 4) { temp += BitConverter.ToInt32(b, k).ToString() + " "; } Messages[1] = new Message(); Messages[1].Text = temp; Messages[1].FromIP = ip.ToString() + " Client"; Messages[1].ToIP = clientIP; _message = RSAEncryptor.Decrypt(b, _publicKey, _computedPrivateKey, i); Messages[2] = new Message(); Messages[2].Text = _message; Messages[2].FromIP = ip.ToString() + " Client"; Messages[2].ToIP = clientIP; s.Close(); myListener.Stop(); }