System.out.println("Enter value of M: ");import java.io.*; import java.net.*; import java.util.*; import java.lang.*; import javax.swing.JOptionPane; import java.text.DecimalFormat; import java.text.NumberFormat; import java.math.*; public class EchoClient { public static void main(String[] args) { // declare objects we require Socket localSocket; BufferedReader in; BufferedReader kbdInput; PrintWriter out; String hostname = new String(); String s, s1; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Server IP Address : "); try { hostname = input.readLine( ); } catch(Exception e) { System.out.println("Exception: " + e.getMessage( ) + "has occurred"); } try { // create a socket connected to remote Port 9999; DNS lookup is automatic localSocket = new Socket (hostname, 9999); // acknowledgement of connection request System.out.println(" Connection made with " + localSocket.getInetAddress( ) + "\nRemote Port: " + localSocket.getPort( )+ "\nLocal Port: " + localSocket.getLocalPort( )); // set up data streams in and out of socket and from keyboard in = new BufferedReader(new InputStreamReader(localSocket.getInputStream( ))); out = new PrintWriter(localSocket.getOutputStream( )); kbdInput = new BufferedReader(new InputStreamReader(System.in)); // Lab 2 - (2)(a) Bob uses PublicAlice key to encrypt a plaintext message M BigInteger n,e, p,q,d, exponent; s1 = in.readLine( ); System.out.println("Value of n: "+s1); n = new BigInteger(s1); s1 = in.readLine( ); System.out.println("Value of e: "+s1); e = new BigInteger(s1); // while we have a connection while (true) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); // read keyboard to String //s = kbdInput.readLine( ); // Lab 2 - (2)(b) Bob uses PublicAlice key to encrypt a plaintext message M char M; System.out.println("Enter value of M: "); String word = buff.readLine(); int j = Integer.valueOf(word).intValue(); BigInteger b1 = BigInteger.valueOf(j); BigInteger num = b1.modPow(e,n); NumberFormat matter = new DecimalFormat("#0"); System.out.println(matter.format(num)); out.println(num); out.flush(); //} System.out.println(in.readLine( )); } } catch (UnknownHostException e) { System.out.println(e.getMessage( )); } catch (IOException e) { System.out.println(e.getMessage( )); } } }
String word = buff.readLine();
int j = Integer.valueOf(word).intValue();
i am try to convter a string, like eg: HI into int. However it give me error and how to do anyway?