I tried to insert \0 into my chain and I got this :
1 2 3 4
original : 1111\0111H1... //replace H by a char becoming \0 when crypted with 1213...
result :
1111
1111A111... //A a char different from H appears
Experiment 2 :
1 2 3 4 5 6 7 8 9 10 11
Input : 1111111... (only 1)
Keys : 12131213 12131213 12131213 11
Output :
packet 1 : 1111111111111...
packet 2 : 1100202020203...[pattern]
packet 3 : 202/111111112...[pattern]
packet 4 : 1111111111111...
packet 5 : 1111111100203...[pattern]
Encrypt : ...><=>=>=>=>=>=><...[pattern]
(I can't scroll up to the beginning where it probably was =>=>=> only).
Now test removing the "\0 suppr" code :
1 2 3 4
original : 111\0111H1... //replace H by a char becoming \0 when crypted with 1213...
result :
1111
1111A111... //A a char different from H appears
1 2 3 4 5 6 7
Input : 1111111... (only 1)
Keys : 12131213 12131213 12131213 11
Output :
packet 1 : 1111111002031...[pattern]
Encrypt : ...><=>=>=>=>=>=><...[pattern]
(I can't scroll up to the beginning where it probably was =>=>=> only).
Your problem is simple: Your code, probably, shifting the key with one(or several) position left or right when you unctrypt different packets after first one.
Do you recognize pattern that every first packet is always OK when you receive multiple packets?(Of course, in this test examples, when you don't intervene in data by removing '\0's or something else)
I finally understand what's the problem. When I receive two packets, see what happen :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Key : +1 +2
Original emssage :
packet (p) 1: 111
p2 : 1111
//The packets are splited like this by the network, not by me
Received :
crypted :
p1 : 242
p2 : 4242
Trying to uncrypt like this :
p1 : 2-1 4-2 2-1 -> 121 (so the first packet 111111111)
p2 : 4-1 2-2 4-1 2-2 -> 3030 (so the bug packet)
The problem happens because the key-shift "reset" between the treatment of each packet.
One solution to fix it is maybe to bufferize the sent message, but I can't certify it wont be splitted into packets.
The problem happens because the key-shift "reset" between the treatment of each packet.
So the solution is to use some global variable where to kept last position of the mini key in big key, when first packet finished. And when you start next packet, you skip over and start from last position. Or simply to gather all packets and make them one before use uncrypt
One solution to fix it is maybe to bufferize the sent message, but I can't certify it wont be splitted into packets.
I really don't understand nothing in Socket programing, yet.
Actually the problem isn't the number of keys (because I concat them into one big key) it's about starting the decryption from the beginning of the big-key or not.
but the first packet was sent with an odd number of characters
It's not about odd/even, but about message.size()%text_key.size()==0 or not.
I'll add a flag to now if this is the last packet or not, and, with a global variable, keep the correct shift.
EDIT : When I'm talking about "packet", it is not the same than "splitting by bufsize".
Ex:
bufsize = 10
Total msg size = 43
Network packet size : 25
||
V
p1 : 10+10+5 -> clear text
p2 : 10+8 -> bug text
To see the separation between each packet, I search for the "<from>" beacon, because this beacon appear only once per reconsitued message.
I really don't understand nothing from client/server programing. I also was thinking that he start to uncrypt() when the accumulation finished. This is why I ask him to make test with '111111...' and specific keys, to catch what symbols are input between messages that shift the keys. I also surpize when I was seeing that he uncript different packs separated.
Don't worry, I'll apply a modulo (and you missunderstand a bit what I mean by packet, because packet 1 and packet 2 are not in the same msg variable, it's treated like if I received 2 totally different messages).
And don't care about misunderstandings - it is important on the end you to clear your bug. The People use different "languages", depending of their knowledge. Sockets are "black night" for me, English is not my native language and so on.
I'm working on the problem. I still have some problem to keep the correct SHIFT, however I printed the full text in "semi-clear" (I mean it's uncrypted, but there are parasit so I'm working on shifting right now).
I'll put my code here when the entire problem will be solved.