fujii13

03-23-2005, 04:34 PM

new to the forums. i'm kinda confused here. and could use your guys' help.

this is a section of code from a base64 decoding/3DES decrypting script i'm working w/. the first lines of this for statement "left" and "right" is what i'm having problems with.

when does incrementation happen in these statements?

for (var j=0; j<iterations; j++) { //either 1 or 3 iterations

left = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);

right = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);

temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; right ^= temp; left ^= (temp << 4);

temp = ((right >>> -16) ^ left) & 0x0000ffff; left ^= temp; right ^= (temp << -16);

temp = ((left >>> 2) ^ right) & 0x33333333; right ^= temp; left ^= (temp << 2);

temp = ((right >>> -16) ^ left) & 0x0000ffff; left ^= temp; right ^= (temp << -16);

temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1);

temp = ((right >>> 8) ^ left) & 0x00ff00ff; left ^= temp; right ^= (temp << 8);

temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1);

//the right side needs to be shifted and to get the last four bits of the left side

temp = (left << 8) | ((right >>> 20) & 0x000000f0);

//left needs to be put upside down

left = (right << 24) | ((right << 8) & 0xff0000) | ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0);

right = temp;

//now go through and perform these shifts on the left and right keys

for (i=0; i < shifts.length; i++) {

//shift the keys either one or two bits to the left

if (shifts[i]) {left = (left << 2) | (left >>> 26); right = (right << 2) | (right >>> 26);}

else {left = (left << 1) | (left >>> 27); right = (right << 1) | (right >>> 27);}

left &= -0xf; right &= -0xf;

//now apply PC-2, in such a way that E is easier when encrypting or decrypting

//this conversion will look like PC-2 except only the last 6 bits of each byte are used

//rather than 48 consecutive bits and the order of lines will be according to

//how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7

lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf]

| pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(left >>> 16) & 0xf]

| pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf]

| pc2bytes6[(left >>> 4) & 0xf];

righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf]

| pc2bytes9[(right >>> 20) & 0xf] | pc2bytes10[(right >>> 16) & 0xf]

| pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf]

| pc2bytes13[(right >>> 4) & 0xf];

temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff;

keys[n++] = lefttemp ^ temp; keys[n++] = righttemp ^ (temp << 16);

}

} //for each iterations

eg. let's say m=0.

does the incrementation happen at each instance of "m++", so that at the end of left and right, m=8?

does the incrementation happen at the end of each statement only once (for each "left" and "right") making m=2?

does incrementation only happen once per for loop? making m=1?

i have no way of putting an alreat in the middle of these statements, so i haven't been able to find out on my own. any help would be greatly appreciated.

TIA.

this is a section of code from a base64 decoding/3DES decrypting script i'm working w/. the first lines of this for statement "left" and "right" is what i'm having problems with.

when does incrementation happen in these statements?

for (var j=0; j<iterations; j++) { //either 1 or 3 iterations

left = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);

right = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);

temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; right ^= temp; left ^= (temp << 4);

temp = ((right >>> -16) ^ left) & 0x0000ffff; left ^= temp; right ^= (temp << -16);

temp = ((left >>> 2) ^ right) & 0x33333333; right ^= temp; left ^= (temp << 2);

temp = ((right >>> -16) ^ left) & 0x0000ffff; left ^= temp; right ^= (temp << -16);

temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1);

temp = ((right >>> 8) ^ left) & 0x00ff00ff; left ^= temp; right ^= (temp << 8);

temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1);

//the right side needs to be shifted and to get the last four bits of the left side

temp = (left << 8) | ((right >>> 20) & 0x000000f0);

//left needs to be put upside down

left = (right << 24) | ((right << 8) & 0xff0000) | ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0);

right = temp;

//now go through and perform these shifts on the left and right keys

for (i=0; i < shifts.length; i++) {

//shift the keys either one or two bits to the left

if (shifts[i]) {left = (left << 2) | (left >>> 26); right = (right << 2) | (right >>> 26);}

else {left = (left << 1) | (left >>> 27); right = (right << 1) | (right >>> 27);}

left &= -0xf; right &= -0xf;

//now apply PC-2, in such a way that E is easier when encrypting or decrypting

//this conversion will look like PC-2 except only the last 6 bits of each byte are used

//rather than 48 consecutive bits and the order of lines will be according to

//how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7

lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf]

| pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(left >>> 16) & 0xf]

| pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf]

| pc2bytes6[(left >>> 4) & 0xf];

righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf]

| pc2bytes9[(right >>> 20) & 0xf] | pc2bytes10[(right >>> 16) & 0xf]

| pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf]

| pc2bytes13[(right >>> 4) & 0xf];

temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff;

keys[n++] = lefttemp ^ temp; keys[n++] = righttemp ^ (temp << 16);

}

} //for each iterations

eg. let's say m=0.

does the incrementation happen at each instance of "m++", so that at the end of left and right, m=8?

does the incrementation happen at the end of each statement only once (for each "left" and "right") making m=2?

does incrementation only happen once per for loop? making m=1?

i have no way of putting an alreat in the middle of these statements, so i haven't been able to find out on my own. any help would be greatly appreciated.

TIA.