Crazy encrypting algo

Pages: 1234
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). 



1
2
Input : 1111111... (only 1)
Keys : 12131213 12131213 12131213 11



What is this 11 key on the end?

I want exactly Keys : 12131213 12131213 12131213 12131213

Don't make variations alone, because I cant interpret right end result.
Last edited on
Sorry I forget to precise that the first test is made with the 1213 key only.
Last edited on
Make only this and show me the result. Don't touch anything else. Leave '\0' alone, don't remove them!

1
2
Input : 1111111... (only 1)
Keys : 12131213 12131213 12131213 12131213 


What you get, when uncrypt?
Last edited on
Only 11111111...

But the output is always correct when keys are equals.
1
2
Input : 1111111... (only 1)
Keys : 1213 1111 1213 1111


Test it, and again results.
1
2
Crypt : <<=><<=><<=><<...
Uncrypt : 111111...
1
2
Input : 1111111... (only 1)
Keys : 1111 1111 1111 11


AND

1
2
Input : 1111111... (only 1)
Keys : 1111 1111 1111 12


Again. Results.
Case 1 : 11111111
Case 2 :
packet 1 : 11111111
packet 2 : 1121110...[pattern]
Now very important question?


Case 2:
packet 1 : 11111111
packet 2 : 1121110...[pattern]

'
Do you see in packet 2, symbols different from '1', '0' and '2'?

As it is in this example: with '%'

1111111111%1102111110211111$121111012111%0112111011211101121110112111011211101121
Last edited on
If you don't have different symbols from '1', '0' and '2' in distort packet, in this case


Input : 1111111... (only 1)
Keys : 1111 1111 1111 12
Case 2:
packet 1 : 11111111
packet 2 : 1121110...[pattern]


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)


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]


So can I see your code, how you synchronize the KEYs POSITIONS in new fragment packet, before you start to uncrypt it?

Do you see this:

packet 3 : 202/111111112...[pattern]


but

Ascii
/ - 47
0 - 48
1 - 49
2 - 50


Your keys are:

Keys : 12131213 12131213 12131213 11


So you have mini-keys 12, 13 and 11.

And because you have only '1'

Input : 1111111... (only 1)


you can obtain:


49+11 = 60 ('<')
49+12 = 61 ('=')
49+13 = 62 ('>')


but when you uncrypt and shift the keys you can obtain:


62 - 13 = 49 ('1')
62 - 12 = 50 ('2')
62 - 11 = 51 ('3')

61 - 13 = 48 ('0')
61 - 12 = 49 ('1')
61 - 11 = 50 ('2')

60 - 13 = 47 ('/')
60 - 12 = 48 ('0')
60 - 11 = 49 ('1')


As I said: You don't synchronize your keys position right, before you start uncrypt.


Last edited on
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.
Last edited on
Emil Enchev wrote:
gather all packets and make them one before use uncrypt


But surely @Zaap was doing that in the original code
http://www.cplusplus.com/forum/general/256776/#msg1122686

Variable str seems to be accumulated from multiple packets before it is sent for decryption.
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.
Last edited on
lastchance,

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.


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).


Lets try with global variable, and see what result will be.
Last edited on
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).
I'm confused!

Sorry!
When you deal with the problem - tell me, Zaap.

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.
Last edited on
Sorry I was a bit busy this afternoon

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.
Pages: 1234