Closed SarahYaw closed 3 years ago
Screenshot of output
Essentially the array list isn't handling the differentiation between users properly. It's going to take time to deep dive in the code, but this only happens when there are 3 or more users. Hopefully this won't be a terribly hard fix.
Can confirm the issue is the ArrayList that juggles the clients. It gets confused if there's more than two and just uses the second padd for encryption which is why it's coming across incorrectly. The current code for the client handling is as follows:
for(int i=0; i<sye_TCPServer.arr.size();i++)
{
ClientHandler temp = sye_TCPServer.arr.get(i);
if(temp.index!=this.index)
{ //encrypt
message = encrypt(user +": "+ message+" ("+temp.index+")", temp.padd);
temp.out.println(message);//broadcasting back
temp.out.flush();//ERROR
}
}
I'll probably need to rely on something other than the if statement to juggle correctly since this really only protects against sending out the message to itself. I'll run a few tests on the encapsulating for loop first to be sure there's no simple fix first.
Not sure if this is new but messages from 2 will not show to 3 and vice versa. 1 gets all messages. not fixed by having 1 leave the server. happens only to rejoining people.
the program is sending with the correct padds it's just not (encrypting or decrypting) correctly. Because the server log shows nothing wrong I'm going to test the dissemination encryption first, although it is puzzling the "to" and "from" tags are making it across just fine.
if I move the tag (only the from, which is technically incorrect but acts as sort of a "known plaintext") out from the for loop it no longer remains in-tact so I can assume it has to do with the encryption. if i move the "print to server console" inside the for loop, I get client 1's messages posted twice but client 2's message posted once with ciphertext in place of the second post. If i understand this correctly, it means the message going though the loop is being encrypted for each user within the arrayList. so client 3's message is encrypted to 1's code, sent, NOT reset, then encrypted AGAIN to client 2's code. this makes a lot of sense looking at the loop. I'm going to try adding a decrypt as the last line to get the message back to plaintext after each iteration so there's no double encryption.
sarah has estabished a connection to Sarahs-MBP
G: 2849; N: 381; Session-Key: 295; padd: 00100111
sarah: hi
sarah: hi; padd: 61; before enc
sarah: 78 92 79 92 85 7 29 85 84 ; padd: 61; after enc
sarah: i{h{r :rs; padd: 61; after dec
sarah: i{h{r :rs; padd: 105; before enc
sarah: 26 8 27 8 1 83 73 0 18 1 18 27 73 83 27 26 ; padd: 105; after enc
sarah: =/</&tn'5&5<nt<=; padd: 105; after dec
sarah has left the chat.
output snippet on server console Upon adding decrypt and some print statements, I'm definitely not seeing something important. I'm going to take a look at the server and client encryption and decryption statements. The issue is with the server side decryption, I'm just not sure what exactly the problem is
I changed the 'pad' variable name to "pad" instead of 'this.padd' which is a global variable. Saw the issue right away haha.
Not sure if this is new but messages from 2 will not show to 3 and vice versa. 1 gets all messages. not fixed by having 1 leave the server. happens only to rejoining people.
This problem is also solved.
first task is diagnosing why its broken