I have the following decryption code which compiles correctly using both GCC in windows (using MingW) and in ubuntu linux. However, only the windows code works correctly to decrypt an encrypted file. The code is exactly the same in both. I am stumped and as we are moving our server to linux we need to have the decryption program working on linux. Any ideas or help is greatly appreciated.
Here is the code:
Code:
#include <stdio.h>
#include <time.h>
#include <string.h>
void decode(unsigned long* v, unsigned long* k);
void code(long *v, long *k);
//int main(int argc, char *argv[]) {
int main() {
// FILE *incoming;
FILE *outgoing;
// FILE *outbound;
FILE *inbound;
//unsigned char input[9]="";
unsigned char incipher[15];
unsigned char unscramble[15];
char file_select1[15] = "";
char file_select2[15] = "";
// char spacer = ' ';
int current = 0;
unsigned long output[2], key[4];
int i = 0;
key[0] = 37444384;
key[1] = 02229721;
key[2] = 21338835;
key[3] = 97034809;
current = 0;
//sprintf(file_select1, "%s", argv[1]);
inbound = fopen("/home/parallels/codeblocks/encrypt/newtea/bin/Debug/TEST.TXT","r");
if(NULL == inbound)
{
printf("\n fopen() inbound Error!!!\n");
return 1;
}
//sprintf(file_select2, "%s", argv[2]);
//outgoing = fopen("track.txt", "wb");
outgoing = fopen("/home/parallels/codeblocks/encrypt/newtea/bin/Debug/DECRYPT.txt","w");
if(NULL == outgoing)
{
printf("\n fopen() outgoing Error!!!\n");
return 1;
}
while (current == 0) {
if (fread(incipher, 8, 1, inbound) != 0) {
output[0] = incipher[0];
output[0] += incipher[1] << 8;
output[0] += incipher[2] << 16;
output[0] += incipher[3] << 24;
output[1] = incipher[4];
output[1] += incipher[5] << 8;
output[1] += incipher[6] << 16;
output[1] += incipher[7] << 24;
} else
break;
decode(output, key);
unscramble[0] = output[0] & 0xFF;
unscramble[1] = (output[0] >> 8) & 0xFF;
unscramble[2] = (output[0] >> 16) & 0xFF;
unscramble[3] = (output[0] >> 24) & 0xFF;
unscramble[4] = output[1] & 0xFF;
unscramble[5] = (output[1] >> 8) & 0xFF;
unscramble[6] = (output[1] >> 16) & 0xFF;
unscramble[7] = (output[1] >> 24) & 0xFF;
for (i = 0; i < 8; i++)
fputc(unscramble[i], outgoing);
}
fclose(outgoing);
fclose(inbound);
return 0;
}
void decode(unsigned long* v, unsigned long* k) {
unsigned long n = 32, sum, y = v[0], z = v[1], delta = 0x2e1889b4;
sum = delta << 5;
// start cycle //
while (n-- > 0) {
z -= ((y << 4) + k[2]) ^ (y + sum) ^ ((y >> 5) + k[3]);
y -= ((z << 4) + k[0]) ^ (z + sum) ^ ((z >> 5) + k[1]);
sum -= delta;
}
// end cycle //
v[0] = y;
v[1] = z;
}
void code(long *v, long *k) {
unsigned long y = v[0], z = v[1], sum = 0, /* set up */
delta = 0x2e1889b4, /* a key schedule constant */
n = 32;
while (n-- > 0) { /* basic cycle start */
sum += delta;
y += ((z << 4) + k[0]) ^ (z + sum) ^ ((z >> 5) + k[1]);
z += ((y << 4) + k[2]) ^ (y + sum) ^ ((y >> 5) + k[3]);
} /* end cycle */
v[0] = y;
v[1] = z;
}