diff --git a/Q2.class b/Q2.class new file mode 100644 index 0000000..1d2c241 Binary files /dev/null and b/Q2.class differ diff --git a/Q2.java b/Q2.java new file mode 100644 index 0000000..2c15008 --- /dev/null +++ b/Q2.java @@ -0,0 +1,39 @@ +public class Q2 { + +//Setup_Request: Hello + +//SETUP: Server's RSA public key + +//Client_Hello:IDc + +//Server_Hello: IDs , SID + +//Ephemeral DH exchange + +//Finished, check the shared key + +//Data exchange + +/** + * Opens the client and server in seperate terminals + * @param args + */ +public static void main(String[] args) +{ + // try + // { + // Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"java Q2Server\""); + // Thread.sleep(500); //Just to ensure the server has enough time to open + // Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"java Q2Client\""); + // } + // catch (Exception e) + // { + // e.printStackTrace(); + // } + + Q2Tools toolbox = new Q2Tools(); + + toolbox.fastModularExpon(5, 117, 19); +} + +} \ No newline at end of file diff --git a/Q2Client.class b/Q2Client.class new file mode 100644 index 0000000..031fe75 Binary files /dev/null and b/Q2Client.class differ diff --git a/Q2Client.java b/Q2Client.java new file mode 100644 index 0000000..f5b702f --- /dev/null +++ b/Q2Client.java @@ -0,0 +1,37 @@ +import java.net.Socket; +import java.io.*; + +public class Q2Client { + + private Socket s; + + public static void main(String[] args) + { + System.out.println("Runing Client"); + Q2Client client = new Q2Client(); + client.run(); + } + + public void run() + { + try + { + s = new Socket("localhost", 4321); + + DataOutputStream dout=new DataOutputStream(s.getOutputStream()); + dout.writeUTF("Hello"); //Setup_Request + //dout.flush(); + + + + + dout.close(); + + s.close(); + } + catch (Exception e) + { + System.out.println("Client Socket failed to connect."); + } + } +} \ No newline at end of file diff --git a/Q2Server.class b/Q2Server.class new file mode 100644 index 0000000..3f8f4ef Binary files /dev/null and b/Q2Server.class differ diff --git a/Q2Server.java b/Q2Server.java new file mode 100644 index 0000000..6e67888 --- /dev/null +++ b/Q2Server.java @@ -0,0 +1,39 @@ +import java.net.ServerSocket; +import java.net.Socket; + +import java.io.*; + +public class Q2Server { + + private ServerSocket ss; + private Socket s; + + public static void main(String[] args) + { + System.out.println("Runing Server"); + Q2Server server = new Q2Server(); + server.run(); + } + public void run() + { + try + { + ss = new ServerSocket(4321); + s = ss.accept(); + + DataInputStream dis=new DataInputStream(s.getInputStream()); + String str=(String)dis.readUTF(); + System.out.println("message= "+str); + + ss.close(); + } + catch (Exception e) + { + System.out.println("Server Failed"); + System.out.println(e); + } + } + + + +} \ No newline at end of file diff --git a/Q2Tools.java b/Q2Tools.java new file mode 100644 index 0000000..9b3e84d --- /dev/null +++ b/Q2Tools.java @@ -0,0 +1,70 @@ +import java.math.BigInteger; + +public class Q2Tools { + + Q2Tools() + { + //Nothing to do here + } + + public void generateRSA() + { + + int e = 65537; + + //Generate p + + //Generate q + + + + } + + /** + * A^B mod C + * @param A + * @param B + * @param C + */ + public void fastModularExpon(int A, int B, int C) + { + String bInBinary = Integer.toBinaryString(B); + + int test = 0; + + System.out.println(bInBinary); + + int k = 0; + for(int i = bInBinary.length()-1; i >= 0; i--) + { + + if(bInBinary.charAt(i)=='1') + { + double temp = Math.pow(2, k); + System.out.println(2+"^"+k+"="+temp); + test += temp; + } + else + { + System.out.println(0+"^"+k+"=0"); + } + k++; + } + + System.out.println(test); + } + + /** + * Simply wrapper for Integer.toBinaryString + * @param number integer to be converted to binary + * @return binary of number as an Biginteger + */ + public BigInteger convertToBinaryBigInt(int number) + { + //Take input number, convert to binary string + String binaryString = Integer.toBinaryString(number); + BigInteger bigBinary = new BigInteger(binaryString); + return bigBinary; + } + +}