Does anyone know C and GCBASIC?
Quote from james789 on March 26, 2024, 3:20 pmI tried to translate the PC1 encryption algorithm from C (.ino) to GCB but it doesn't give the expected results.The algorithm works fine in C:https://simulide.com/p/forum/topic/byte-by-byte-serial-data-encryption-with-128-bit-pc1-encryption-algorithm/With the key: unsigned char crypt_key[16]={0xD4,0xB7,0xE3,0xE8,0x88,0x4C,0x3C,0x54,0x95,0x3F,0x71,0xAA,0x42,0x75,0xBA,0xD1};we need to get the following first 10 encrypted bytes:
102 196 14 158 53 78 114 80 10 129
But with my GCB translation I get instead:95 94 245 12 91 218 241 168 87 214
When I use the key in this form :key = 0xD4,0xB7,0xE3,0xE8,0x88,0x4C,0x3C,0x54,0x95,0x3F,0x71,0xAA,0x42,0x75,0xBA,0xD1
And even worse if I use the key in this other form key(1)=... key(2)=... (when it should be the same, right?), I get:48 1 218 227 20 165 158 23 248 233
key(1)=0xd4
key(2)=0xb7
key(3)=0xe3
key(4)=0xe8
key(5)=0x88
key(6)=0x4c
key(7)=0x3c
key(8)=0x54
key(9)=0x95
key(10)=0x3f
key(11)=0x71
key(12)=0xaa
key(13)=0x42
key(14)=0x75
key(15)=0xba
key(16)=0xd1I know that in GCB the Arrays start at 1 and not 0, but it doesn't work anyway.Does anyone understand where the bug is?
we need to get the following first 10 encrypted bytes:
102 196 14 158 53 78 114 80 10 129
95 94 245 12 91 218 241 168 87 214
key = 0xD4,0xB7,0xE3,0xE8,0x88,0x4C,0x3C,0x54,0x95,0x3F,0x71,0xAA,0x42,0x75,0xBA,0xD1
48 1 218 227 20 165 158 23 248 233
key(1)=0xd4
key(2)=0xb7
key(3)=0xe3
key(4)=0xe8
key(5)=0x88
key(6)=0x4c
key(7)=0x3c
key(8)=0x54
key(9)=0x95
key(10)=0x3f
key(11)=0x71
key(12)=0xaa
key(13)=0x42
key(14)=0x75
key(15)=0xba
key(16)=0xd1
Quote from arcachofo on March 26, 2024, 4:22 pmSome tips:
- Add the code from pc1.gcb to 16F663_sender.gcb instead of including it.
- Open MCU Monitor and click on "RAM" tab to see what is actually happening.
- Use the debugger to go through the code step by step.
Some hints:
This does not work (nothing happens in the RAM:
key = 0xD4,0xB7,0xE3,0xE8,0x88,0x4C,0x3C,0x54,0x95,0x3F,0x71,0xAA,0x42,0x75,0xBA,0xD1This does work (values are stored in memory):
key(1)=0xd4
key(2)=0xb7
...
...
Check this function InitPc1:
for i = 1 to 8
wkey(i) = FnLSR(key(i * 2), 8) or key(i * 2 + 1)8x2+1 = 17
Some tips:
- Add the code from pc1.gcb to 16F663_sender.gcb instead of including it.
- Open MCU Monitor and click on "RAM" tab to see what is actually happening.
- Use the debugger to go through the code step by step.
Some hints:
This does not work (nothing happens in the RAM:
key = 0xD4,0xB7,0xE3,0xE8,0x88,0x4C,0x3C,0x54,0x95,0x3F,0x71,0xAA,0x42,0x75,0xBA,0xD1
This does work (values are stored in memory):
key(1)=0xd4
key(2)=0xb7
...
...
Check this function InitPc1:
for i = 1 to 8
wkey(i) = FnLSR(key(i * 2), 8) or key(i * 2 + 1)
8x2+1 = 17
Quote from james789 on March 27, 2024, 5:26 pm
- Add the code from pc1.gcb to 16F663_sender.gcb instead of including it.
Check this function InitPc1:
for i = 1 to 8
wkey(i) = FnLSR(key(i * 2), 8) or key(i * 2 + 1)8x2+1 = 17
Thank you very much.
I corrected :
for i = 1 to 8
wkey(i) = FnLSR(key( (i-1) * 2)+1, 8) or key( ((i-1)*2) + 2)
next i
What could be the problem if i use include pc1.gcb?
I try to use the MCU monitor but i can only view "data", why ?
- Add the code from pc1.gcb to 16F663_sender.gcb instead of including it.
Check this function InitPc1:
for i = 1 to 8
wkey(i) = FnLSR(key(i * 2), 8) or key(i * 2 + 1)8x2+1 = 17
Thank you very much.
I corrected :
for i = 1 to 8
wkey(i) = FnLSR(key( (i-1) * 2)+1, 8) or key( ((i-1)*2) + 2)
next i
What could be the problem if i use include pc1.gcb?
I try to use the MCU monitor but i can only view "data", why ?
Quote from arcachofo on March 27, 2024, 6:53 pmWhat could be the problem if i use include pc1.gcb?
No problem, but you can't debug that code.
If you include that code in the main file then you can debug step by step and see what is really happening in every code line.
I try to use the MCU monitor but i can only view "data", why ?
If you are using 1.0.0, watch this:
https://www.youtube.com/watch?v=uVwMEadtIEM
What could be the problem if i use include pc1.gcb?
No problem, but you can't debug that code.
If you include that code in the main file then you can debug step by step and see what is really happening in every code line.
I try to use the MCU monitor but i can only view "data", why ?
If you are using 1.0.0, watch this:
https://www.youtube.com/watch?v=uVwMEadtIEM
Quote from james789 on March 27, 2024, 7:39 pmI watched the video but that doesn't solve my problem. In my case, I want to display "Key". On the left of the MCU, I don't have "Key" and if I add "Key" manually, the MCU doesn't find the variable. The video doesn't tell me how to fix this.There's something I'm doing wrong but I don't know what. I add "key" by typing "key" in the name box. If i type "data" the variable is found :
Quote from arcachofo on March 27, 2024, 7:58 pmWhen there are more than one MCU in the circuit you need to set the "Main MCu" (yellow dot) to match what you are doing in the Editor:
https://simulide.com/p/compiler/#compilingIf the yellow dot is in the reciver then you are uploading to that MCU.
When there are more than one MCU in the circuit you need to set the "Main MCu" (yellow dot) to match what you are doing in the Editor:
https://simulide.com/p/compiler/#compiling
If the yellow dot is in the reciver then you are uploading to that MCU.
Quote from james789 on March 27, 2024, 8:25 pmthanks. but why are i,j, key(16) and wkey(8) empty ? SimulIDE add the whole variables itself. And if i add "key" there is no Address too, why ?
thanks. but why are i,j, key(16) and wkey(8) empty ? SimulIDE add the whole variables itself. And if i add "key" there is no Address too, why ?
Quote from james789 on March 27, 2024, 8:51 pmDoes the MCU also work with C.ino files (I can't see any variables).Do I also need to delete #include in.ino files if I want to be able to debug?
Quote from arcachofo on March 27, 2024, 9:14 pmwhy are i,j, key(16) and wkey(8) empty ?
Declare them one by one.
Does the MCU also work with C.ino files (I can't see any variables).
Only works with global variables.
why are i,j, key(16) and wkey(8) empty ?
Declare them one by one.
Does the MCU also work with C.ino files (I can't see any variables).
Only works with global variables.
Quote from james789 on March 27, 2024, 10:11 pmThis is very strange behavior. As we can see, some variables are displayed, others are not. Couldn't we consider this a bug? Wouldn't it be possible for Simulide to display the variables correctly every time?