11package dev .abhay7 .skribbl .client ;
22
3- import java .nio .charset .StandardCharsets ;
3+ // import java.nio.charset.StandardCharsets;
44
55import javax .swing .Box ;
66import javax .swing .BoxLayout ;
1212
1313import com .formdev .flatlaf .FlatIntelliJLaf ;
1414
15- import dev .abhay7 .skribbl .client .jameskwong .pwdsignal .PWDSignalSession ;
15+ // import dev.abhay7.skribbl.client.jameskwong.pwdsignal.PWDSignalSession;
1616
1717public class Main {
1818
@@ -28,122 +28,122 @@ public static void main(String[] args) {
2828 return ;
2929 }
3030
31- try {
32- System .out .println ("TEST CASE 1 -- NORMAL OPERATIONS" );
33- PWDSignalSession alice = new PWDSignalSession ("Test123" , true );
31+ // try {
32+ // System.out.println("TEST CASE 1 -- NORMAL OPERATIONS");
33+ // PWDSignalSession alice = new PWDSignalSession("Test123", true);
3434
35- PWDSignalSession bob = new PWDSignalSession ("Test123" , false );
35+ // PWDSignalSession bob = new PWDSignalSession("Test123", false);
3636
37- byte [] alicePayload1 = alice .createPayload1 ();
38- byte [] bobPayload1 = bob .createPayload1 ();
37+ // byte[] alicePayload1 = alice.createPayload1();
38+ // byte[] bobPayload1 = bob.createPayload1();
3939
40- alice .acceptPayload1 (bobPayload1 , 0 );
41- bob .acceptPayload1 (alicePayload1 , 0 );
40+ // alice.acceptPayload1(bobPayload1, 0);
41+ // bob.acceptPayload1(alicePayload1, 0);
4242
43- // payload 1 done
43+ // // payload 1 done
4444
45- byte [] alicePayload2 = alice .createPayload2 ();
46- byte [] bobPayload2 = bob .createPayload2 ();
45+ // byte[] alicePayload2 = alice.createPayload2();
46+ // byte[] bobPayload2 = bob.createPayload2();
4747
48- alice .acceptPayload2 (bobPayload2 , 0 );
49- bob .acceptPayload2 (alicePayload2 , 0 );
48+ // alice.acceptPayload2(bobPayload2, 0);
49+ // bob.acceptPayload2(alicePayload2, 0);
5050
51- // Payload 2 done
51+ // // Payload 2 done
5252
53- byte [] alicePayload3 = alice .createPayload3 ();
54- byte [] bobPayload3 = bob .createPayload3 ();
53+ // byte[] alicePayload3 = alice.createPayload3();
54+ // byte[] bobPayload3 = bob.createPayload3();
5555
56- alice .acceptPayload3 (bobPayload3 , 0 );
57- bob .acceptPayload3 (alicePayload3 , 0 );
56+ // alice.acceptPayload3(bobPayload3, 0);
57+ // bob.acceptPayload3(alicePayload3, 0);
5858
59- System .out .println ("Alice state: " + alice .getState ());
60- System .out .println ("Bob state: " + bob .getState ());
59+ // System.out.println("Alice state: " + alice.getState());
60+ // System.out.println("Bob state: " + bob.getState());
6161
62- System .out .println ();
62+ // System.out.println();
6363
64- String message = "Hi bob! I'm alice" ;
65- byte [] messageBytes = message .getBytes ();
66- byte [] messageBytesEncrypted = alice .encryptSendPacket (messageBytes , 0 , messageBytes .length );
64+ // String message = "Hi bob! I'm alice";
65+ // byte[] messageBytes = message.getBytes();
66+ // byte[] messageBytesEncrypted = alice.encryptSendPacket(messageBytes, 0, messageBytes.length);
6767
68- System .out .println ("Original message: " + new String (messageBytes , StandardCharsets .UTF_8 ));
69- System .out .println ();
70- System .out .println ("Encrypted message: " + new String (messageBytesEncrypted , StandardCharsets .UTF_8 ));
71- System .out .println ();
68+ // System.out.println("Original message: " + new String(messageBytes, StandardCharsets.UTF_8));
69+ // System.out.println();
70+ // System.out.println("Encrypted message: " + new String(messageBytesEncrypted, StandardCharsets.UTF_8));
71+ // System.out.println();
7272
73- byte [] messageBytesDecrypted = bob .decryptReceivePacket (messageBytesEncrypted , 0 , messageBytesEncrypted .length );
74- System .out .println ("Bob's POV: " + new String (messageBytesDecrypted , StandardCharsets .UTF_8 ));
75- System .out .println ();
73+ // byte[] messageBytesDecrypted = bob.decryptReceivePacket(messageBytesEncrypted, 0, messageBytesEncrypted.length);
74+ // System.out.println("Bob's POV: " + new String(messageBytesDecrypted, StandardCharsets.UTF_8));
75+ // System.out.println();
7676
77- message = "Yo whats good Alice?" ;
78- messageBytes = message .getBytes ();
79- messageBytesEncrypted = bob .encryptSendPacket (messageBytes , 0 , messageBytes .length );
77+ // message = "Yo whats good Alice?";
78+ // messageBytes = message.getBytes();
79+ // messageBytesEncrypted = bob.encryptSendPacket(messageBytes, 0, messageBytes.length);
8080
81- System .out .println ("Original message: " + new String (messageBytes , StandardCharsets .UTF_8 ));
82- System .out .println ();
83- System .out .println ("Encrypted message: " + new String (messageBytesEncrypted , StandardCharsets .UTF_8 ));
84- System .out .println ();
81+ // System.out.println("Original message: " + new String(messageBytes, StandardCharsets.UTF_8));
82+ // System.out.println();
83+ // System.out.println("Encrypted message: " + new String(messageBytesEncrypted, StandardCharsets.UTF_8));
84+ // System.out.println();
8585
86- messageBytesDecrypted = alice .decryptReceivePacket (messageBytesEncrypted , 0 , messageBytesEncrypted .length );
87- System .out .println ("Alice's POV: " + new String (messageBytesDecrypted , StandardCharsets .UTF_8 ));
88- System .out .println ();
86+ // messageBytesDecrypted = alice.decryptReceivePacket(messageBytesEncrypted, 0, messageBytesEncrypted.length);
87+ // System.out.println("Alice's POV: " + new String(messageBytesDecrypted, StandardCharsets.UTF_8));
88+ // System.out.println();
8989
90- System .out .println ("\n \n TEST CASE 2 -- REFLECTION ATTACK" );
90+ // System.out.println("\n\nTEST CASE 2 -- REFLECTION ATTACK");
9191
92- // attacker replays Bob's message back to him
92+ // // attacker replays Bob's message back to him
9393
94- try {
95- byte [] reflectionAttack = bob .decryptReceivePacket (messageBytesEncrypted , 0 , messageBytesEncrypted .length );
96- }
97- catch (Exception e ) {
98- System .out .println ("Error ocurred during Reflection attack occurred: " + e .getMessage ());
99- }
94+ // try {
95+ // byte[] reflectionAttack = bob.decryptReceivePacket(messageBytesEncrypted, 0, messageBytesEncrypted.length);
96+ // }
97+ // catch (Exception e) {
98+ // System.out.println("Error ocurred during Reflection attack occurred: " + e.getMessage());
99+ // }
100100
101- System .out .println ("\n \n TEST CASE 3 -- REPLAY ATTACK" );
101+ // System.out.println("\n\nTEST CASE 3 -- REPLAY ATTACK");
102102
103103
104- try {
105- byte [] replayAttack = alice .decryptReceivePacket (messageBytesEncrypted , 0 , messageBytesEncrypted .length );
106- }
107- catch (Exception e ) {
108- System .out .println ("Error ocurred during replay attack occurred: " + e .getMessage ());
109- }
104+ // try {
105+ // byte[] replayAttack = alice.decryptReceivePacket(messageBytesEncrypted, 0, messageBytesEncrypted.length);
106+ // }
107+ // catch (Exception e) {
108+ // System.out.println("Error ocurred during replay attack occurred: " + e.getMessage());
109+ // }
110110
111- System .out .println ("\n \n TEST CASE 4 -- WRONG PASSWORD" );
111+ // System.out.println("\n\nTEST CASE 4 -- WRONG PASSWORD");
112112
113- alice = new PWDSignalSession ("Test123" , true );
113+ // alice = new PWDSignalSession("Test123", true);
114114
115- bob = new PWDSignalSession ("Bruh" , false );
115+ // bob = new PWDSignalSession("Bruh", false);
116116
117- alicePayload1 = alice .createPayload1 ();
118- bobPayload1 = bob .createPayload1 ();
117+ // alicePayload1 = alice.createPayload1();
118+ // bobPayload1 = bob.createPayload1();
119119
120- alice .acceptPayload1 (bobPayload1 , 0 );
121- bob .acceptPayload1 (alicePayload1 , 0 );
120+ // alice.acceptPayload1(bobPayload1, 0);
121+ // bob.acceptPayload1(alicePayload1, 0);
122122
123- // payload 1 done
123+ // // payload 1 done
124124
125- alicePayload2 = alice .createPayload2 ();
126- bobPayload2 = bob .createPayload2 ();
125+ // alicePayload2 = alice.createPayload2();
126+ // bobPayload2 = bob.createPayload2();
127127
128- alice .acceptPayload2 (bobPayload2 , 0 );
129- bob .acceptPayload2 (alicePayload2 , 0 );
128+ // alice.acceptPayload2(bobPayload2, 0);
129+ // bob.acceptPayload2(alicePayload2, 0);
130130
131- // Payload 2 done
131+ // // Payload 2 done
132132
133- alicePayload3 = alice .createPayload3 ();
134- bobPayload3 = bob .createPayload3 ();
133+ // alicePayload3 = alice.createPayload3();
134+ // bobPayload3 = bob.createPayload3();
135135
136- alice .acceptPayload3 (bobPayload3 , 0 );
137- bob .acceptPayload3 (alicePayload3 , 0 );
136+ // alice.acceptPayload3(bobPayload3, 0);
137+ // bob.acceptPayload3(alicePayload3, 0);
138138
139- System .out .println ("Alice state: " + alice .getState ());
140- System .out .println ("Bob state: " + bob .getState ());
139+ // System.out.println("Alice state: " + alice.getState());
140+ // System.out.println("Bob state: " + bob.getState());
141141
142- System .out .println ();
143- }
144- catch (Exception e ) {
145- System .out .println ("Error occurred during wrong password attack: " + e .getMessage ());
146- }
142+ // System.out.println();
143+ // }
144+ // catch (Exception e) {
145+ // System.out.println("Error occurred during wrong password attack: " + e.getMessage());
146+ // }
147147 }
148148
149149 private static String [] promptForStartupData () {
@@ -170,14 +170,14 @@ private static String[] promptForStartupData() {
170170 String username = usernameField .getText ().trim ();
171171 String serverInput = serverField .getText ().trim ();
172172
173- if (!username .isEmpty () && serverInput .matches ("^.+:\\ d+$" ) && username .length () < 15 ) {
173+ if (!username .isEmpty () && serverInput .matches ("^.+:\\ d+$" ) && username .length () < 15 && username . indexOf ( ":" ) < 0 ) {
174174 String [] parts = serverInput .split (":" );
175175
176176 toRet [0 ] = username ;
177177 toRet [1 ] = parts [0 ];
178178 toRet [2 ] = Integer .parseInt (parts [1 ]) + "" ;
179179 } else {
180- JOptionPane .showMessageDialog (null , "Invalid input. Please enter a username (less than 15 characters) and server in IP:PORT format." , "Input Error" , JOptionPane .ERROR_MESSAGE );
180+ JOptionPane .showMessageDialog (null , "Invalid input. Please enter a username (less than 15 characters) without a : and server in IP:PORT format." , "Input Error" , JOptionPane .ERROR_MESSAGE );
181181 }
182182 } else {
183183 JOptionPane .showMessageDialog (null , "User did not proceed with connection." );
0 commit comments