# XOR with char array

I need help please , I need to see the result of `f []` XOR `k1` ...of all element of `f[]`... but i have problem and i don't know how i fixed it ... for exmple : `65 ^ k1 = 237` ;
`66^k1=238`

``````
float x[16] ;
byte b[256] ;
int z ;
float a ;
int tt ;
int r =  4 ;
int i ;
int j ;
int L ;
int f[16][16];
int bprime[16][16];
char fprime[] = {86,237} ;
int k1 = 23;
int k2 = 84 ;
int k3=233;
int k4=172;

void setup() {
Serial.begin(9600);
x[1]= 0.789632145698 ;  //Serial.println(MAT);
}

void loop() {

for (  int i = 2; i <=16 ; i++) {
x[i] = r * (x[i-1]*(1 - x[i-1]));
}
// partie de binairisation
for (  int u = 1; u <= 10 ; u++) {
a=x[u];
i=u-1 ;

for (int k = 0 ; k <= 15; k++){

if (a>=1/pow(2,k)){
a=a-(1/pow(2,k));
b[16*i+k]=1 ;
}
else  {
a=a;
b[16*i+k]= 0;
//Serial.println(a) ;
}
//  Serial.println(b[16*i+k]);
tt=16*u+1;
b[1,tt]=1;

}
}

for (  int i = 0; i <= 15 ; i++){
for (int j = 0; j <= 15 ; j++){
L = i*16+j;

bprime[i][j]= 2*b[L]+b[L+1];
//  Serial.println(bprime[i,j]);
}
}
// cryptage
for (int i = 0 ; i <= 15 ; i++){
for ( int j = 0 ; j <= 15 ; j++){
for (int z=0 ; z<= sizeof(fprime) ; z++){
fprime[sizeof(fprime)]=f[z];
switch (bprime[i][j]) {
case 1:
f[i][j]=f[z]^k1;

break;
case 2:
f[i][j]=f[z]^k3     ;

break;
case 3:
f[i][j]=f[z]^k2;

break;
default:
f[i][j]=f[z]^k4;

break;

}
} Serial.println(fprime[i][j]);
}
}            }

``````

Array indices start from zero.

``````fprime[i,j]);
``````

Did you mean

``````fprime[i][j]);
``````

?

I know it start from 0 but i work frome 1
I mean `fprime[i,j]);`

There are so many issues with the posted code which looks like some sort of poorly performed python port.. Which index are you trying to access with "fprime[i,j]"? And what do you think "f^kn" is going to do?

fprime is a one-dimensional array "i,j" is wrong. "f" is a pointer to an array, "f^kn" is not doing what you expect.

EDIT: As already mentioned, arrays start from 0 and by starting from 1, you waste an element which is a bad idea.

No. You really don't

How's that working for you?

BTW, 16 * 16 is 256

k1 appears to have the value 23.

``````int k1 = 23;
``````

65 XOR 23 is 86 decimal, not 237 (assuming you think the carat symbol ^ is the XOR operator)

Have you changed your calculator batteries recently?

What do you think happens when you try to store a value into array index 16 of an array with only 10 elements?

PS: look up the "C/C++ comma operator".

237 is just an example
Look at the new code, my problem is when the` f []` is an array that the` XOR operator` does not work

Your problem is that your understanding of arrays, array indices and the sizeof operator is flawed.

My problem is that you have edited the original post, and my early answers look stupid.

I hate it when that happens

``````a=a-(1/pow(2,k));
``````

I thought we'd discussed this already, and decided it wasn't appropriate.

That's not something I'd rely on for very long

anyway thank you for help

Find some C/C++ array examples and work through them; you're in over your head with the code you posted.

ok thank you

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.