/*
	JPEG Image Encryption B1
	
	By haxpor (haxpor@haxpor.org)

	Input File: input.jpg
	Output File: dataen.bin
*/

#include <stdio.h>
#include <stdlib.h>

#define WAIT system("PAUSE")
#define BUFFLENGTH 30000

int main(int argc, char *argv[])
{
  unsigned char input[BUFFLENGTH];
  unsigned char key[] = "MEETMEATTOGARPARTY";
  int count=0;
  FILE* file;

  //Read file
  if( (file = fopen("input.jpg", "rb")) != NULL)
  {
		count = fread(input, 1, BUFFLENGTH, file);
		input[count] = '\0';
		printf("Read: %d\n", count);
		fclose(file);
  }
  else{
		printf("Error reading file!!!\n");
		goto EXIT;
  }
  
  //Enter the encryption process
  int i;
  for(i=0; i<count; i++)
  {
		//#1 Encryptiong State 1: XOR each byte with key[]
		input[i] = input[i] ^ key[i % (sizeof(key)-1)];
  }
  
  //Write to output
  //Read file
  if( (file = fopen("dataen.bin", "wb")) != NULL)
  {
		count = fwrite(input, 1, count, file);
		printf("Write: %d\n", count);
		fclose(file);
  }
  else{
		printf("Error reading file for writing!!!\n");
		goto EXIT;
  }
  
  printf("Completed!!!\n");
EXIT:
  WAIT;
  return 0;
}
