Two questions about "simpleserial-aes.c code"

Question 1>

‘simpleserial-aes.c’ code receive a letter through the getch() function and use ‘x’,‘k’,‘p’ as a separator to communicate.
When it contains ‘x’,‘k’ and ‘p’ to the actual plaintext and key, I can’t find the code that determines whether ‘x’,‘k’,‘p’ use as data or a separator.
I would like to know if I can distinguish.

Question 2>

‘simple serial-aes.c’ has a code that turns the state into ‘IDLE’ by using the separator ‘x’ in the first if statement.
Also, the code changes ‘KEY’ or ‘PLAIN’ state to ‘IDLE’ state when I get ‘x’.
Nevertheless, why should I convert to ‘IDLE’ status when it comes to character named ‘x’ in the first if statement?

If the question is somewhat difficult to understand, please understand that I am by the lack of English.

Hello,
Hopefully this is what you are looking for:

This is located in the main file, for example see https://github.com/newaetech/chipwhisperer/blob/master/hardware/victims/firmware/simpleserial-aes/simpleserial-aes.c. Looking around line 111, 117, and 123 it is checking what the received character is. When it detects one of those special characters it then assumes the next block is that data. You can see it setting the “state” variable to different values depending on that character.

This is a bit of a “failsafe”. Basically no matter what, when the system receives an ‘x’ it goes back to the idle state. This is an easy way of getting things back to some known state.

Hello.

We can’t understand still.

How about this?
If the plaintext (or the key) has the letters ‘x’, ‘k’, ‘p’, then there is no problem?

Thx to answer

Hello,

Ah - the plaintext/key are assumed to be in hex. So for example it’s looking for a string that has “k000102030405060708090A0B0C0D0E0F” (followed by a newline). If you wanted to represent that as a UNICODE/ASCII string it would come up as something else. Because it’s limited to the ASCII characters, the key/plaintext won’t have those special characters in it!

Hopefully that makes sense…

Hello, again.
Yes, We exactly want to this.

What do you think of this one that you add some comments about this issue?

Oh, and we have another question.

[another question]
We can analyze the code “simpleserial-aes.c”. but we can’t understanding the mechanism of sending serial message from “CWCapture.pyw”. So can you explain where the code is?