Beispiel #1
0
TEST_P (EncoderOutputTest, CompareOutput) {
  EncodeFileParam p = GetParam();
#if defined(ANDROID_NDK)
  std::string filename = std::string ("/sdcard/") + p.fileName;
  EncodeFile (filename.c_str(), p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, p.isLossless, p.enableLtr, this);
#else
  EncodeFile (p.fileName, p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, p.isLossless, p.enableLtr, this);
#endif
  //will remove this after screen content algorithms are ready,
  //because the bitstream output will vary when the different algorithms are added.
  unsigned char digest[SHA_DIGEST_LENGTH];
  SHA1Result (&ctx_, digest);
  if (!HasFatalFailure()) {
    CompareHash (digest, p.hashStr);
  }
}
Beispiel #2
0
void Defines::Load(String filename)
{
        if (encode)
                EncodeFile(filename, filename+".dc", CRYPT_DEFINES_PASS);
        l->LoadFromFile(encode?filename+".dc":filename);
        _filename = filename;
        if (encode)
                DeleteFile(filename+".dc");
}
Beispiel #3
0
TEST_P (EncoderOutputTest, CompareOutput) {
  EncodeFileParam p = GetParam();
  SEncParamExt EnxParamExt;

  EncFileParamToParamExt (&p, &EnxParamExt);

#if defined(ANDROID_NDK)
  std::string filename = std::string ("/sdcard/") + p.pkcFileName;
  EncodeFile (p.pkcFileName, &EnxParamExt, this);
#else
  EncodeFile (p.pkcFileName, &EnxParamExt, this);
#endif
  //will remove this after screen content algorithms are ready,
  //because the bitstream output will vary when the different algorithms are added.
  unsigned char digest[SHA_DIGEST_LENGTH];
  SHA1Result (&ctx_, digest);
  if (!HasFatalFailure()) {
    CompareHash (digest, p.pkcHashStr);
  }
}
Beispiel #4
0
TEST_P (EncoderOutputTest, CompareOutput) {
  EncodeFileParam p = GetParam();
  EncodeFile (p.fileName, p.usageType , p.width, p.height, p.frameRate, p.slices, p.denoise, p.layers, this);

  //will remove this after screen content algorithms are ready,
  //because the bitstream output will vary when the different algorithms are added.
  unsigned char digest[SHA_DIGEST_LENGTH];
  SHA1Result (&ctx_, digest);
  if (!HasFatalFailure()) {
    CompareHash (digest, p.hashStr);
  }
}
//This function reads char by char from a file and then calls another function to encode the chars into their respective encoded char
/*C*/ void ReadChar(FILE*infile,FILE*outfile,char*actualStr,char*codeStr)
{
    int i;
    char encode[MAX_CHARS]="";

    while(fgets(encode,MAX_CHARS,infile) != NULL) //This will read the infile into a string until there is an error or EOF which it will then stop the while loop
    {
        for (i = 0; i < strlen(encode); i++)
            encode[i] = EncodeFile(encode[i],actualStr,codeStr); //Reading char by char, EncodeFile is called to encode char by char and put each encoded char into the encode string
        fputs(encode, outfile); //prints the encode string into outfile
    }
}
Beispiel #6
0
u32 ppmd_compress	(void *dest_buffer, const u32 &dest_buffer_size, const void *source_buffer, const u32 &source_buffer_size)
{
    PPMd_Lock();
	ppmd_initialize	();

	stream			source(source_buffer,source_buffer_size);
	stream			dest(dest_buffer,dest_buffer_size);
	EncodeFile		(&dest,&source,order_model,restoration_method_cut_off);

	PPMd_Unlock();
	return			(dest.tell() + 1);
}
Beispiel #7
0
int main()
{
    FILE *InputFile=fopen("#InputText.in","r");
    FILE *EncodedFile=fopen("#Output.out","w");
    FILE *CodesFile=fopen("#Keys.out","w");
    FILE *TreeFile=fopen("#Tree.out","w");
    FILE *DecodedFile=fopen("#Decoded.out","w");
    FILE *CompressionFile=fopen("#CRatio.out","w");

	TEXT INPUT[MAX_LEN],OUTPUT[ENCODE_LEN];
	ReadFile(InputFile);
    Huffman(INPUT);
    PrintCodes(CodesFile);
    DisplayTree(&ROOT , LEVEL , TreeFile);                         // Display the Huffman Tree
    DisplayTreeLevels(&ROOT , TreeFile);                           // Display the Huffman Tree by Levels
    HuffmanEncoding(INPUT , OUTPUT);                            // Input -<Encoding>-> Encoded Sequence
    EncodeFile(EncodedFile);
    DecodingHuffman(OUTPUT , TreeTop , DecodedFile);           // Encoded Sequence -<Decoding>-> Decoded Sequence
    compressionRatio(INPUT , OUTPUT , CompressionFile);
	return 0;
}
void CPersistentSymbolToolDlg::OnButtonEncode() 
{
	CFileDialog dlgFileOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY, NULL);
	if(dlgFileOpen.DoModal() == IDOK)
	{
		CFileDialog dlgFileSave(FALSE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, NULL);
		if(dlgFileSave.DoModal() == IDOK)
		{
			try
			{
#if 1
				EncodeFile(dlgFileOpen.GetPathName().GetBuffer(0), dlgFileSave.GetPathName().GetBuffer(0));
#else
				FILE *fp = fopen(dlgFileOpen.GetPathName().GetBuffer(0), "rb");
				unsigned char *bufSrc = new unsigned char[1024*1024];
				memset(bufSrc, 0, 1024*1024);
				fread(bufSrc, 1024*1024, 1, fp);
				int len = strlen((char*)bufSrc);
				fclose(fp);
				unsigned char *bufDst = new unsigned char[len];
				memset(bufDst, 0, len);

				EncodePersistentSymbols(bufDst, bufSrc, len);
				
				fp = fopen(dlgFileSave.GetPathName().GetBuffer(0), "wb");
				fwrite(&len, 4, 1, fp);
				fwrite(bufDst, len, 1, fp);
				fclose(fp);
				delete[] bufSrc;
				delete[] bufDst;
#endif
			}
			catch(...)
			{
				m_strStatus = "Somthing is wrong.";
				UpdateData(FALSE);
			}
		}
	}
}
//This function will decode the encoded file by calling the function above and matching the encoded chars
//with the original char. It then prints out the decoded string.
/*E*/ void DecodeFile(FILE*infile,FILE*outfile,char*actualStr,char*codeStr)
{
    int i;
    char filetoEncodeStr[MAX_CHARS]="";
    char decodeStr[MAX_CHARS]="";

    fputs("\nResults of encoding check:\n", stdout);
    rewind(infile); //Rewinds the infile and outfile to point to the beginning of the files
    rewind(outfile);
    while(fgets(filetoEncodeStr,MAX_CHARS,infile)!=NULL && fgets(decodeStr,MAX_CHARS,outfile)!=NULL) //As long as both do not read errors or EOF, the while loop will continue
    {
        for(i=0;i<strlen(decodeStr);++i)
            decodeStr[i]=EncodeFile(decodeStr[i],codeStr,actualStr); //Uses the encoding function to now decode by returning the original respective character
        if(strcmp(decodeStr,filetoEncodeStr)==0) //Checks if the decoded string is the same as the original string from the file the user wished to have encoded
        {
            if(decodeStr[strlen(decodeStr)-1]=='\n') //In order to print (correct coding) right after the decoded string is printed on the screen,
                decodeStr[strlen(decodeStr)-1]='\0'; //this looks to see if the last character of the decoded string is a newline or not.
            strcat(decodeStr,"(correct coding)\n"); //if it is, the newline will be replaced with \0
        }
    fputs(decodeStr,stdout); //Prints decoded string onto the standard output
    }
}
Beispiel #10
0
void Defines::Save(String filename)
{
        l->SaveToFile(filename);
        if (encode)
                EncodeFile(filename, filename, CRYPT_DEFINES_PASS);
}
Beispiel #11
0
main(){
  struct sockaddr_in server;
  struct sockaddr_in client;
  pid_t pid;
  int sock;
  int sock_client;
  int sin_size;
  int byte_recv;
  char send_data[1024];
  char recv_data[1024];
  struct hostent *host;
  int stat_val;
  pid_t child_pid;

  	    int checkuser, checkpass;

    huffman_node_t *huffmanTree;        /* root of huffman tree */
    int opt;
    char *inFile, *outFile;
    MODES mode;
long numbyte; // number of byte receive
  // Tao kiem soat tin hieu
  signal(SIGCHLD, handle_child);

  if((sock = socket(AF_INET,SOCK_STREAM,0)) == -1) {
    perror("Socket");
    exit(0);
  }
  server.sin_family = AF_INET;
  server.sin_port  = htons(PORT);
  server.sin_addr.s_addr = INADDR_ANY;
  /*   Cach Khac Lay LocalHost
  server.sin_addr = *((struct in_addr *)host->h_addr);
  server.sin_addr.s_addr=inet_ntoa();
  */
  bzero(&(server.sin_zero),8);
  if(bind(sock,(struct sockaddr*)&server,sizeof(struct sockaddr)) == -1){
    perror("bind() error!!");
    exit(0);
  }
  if(listen(sock,BACKLOG) == -1){
    perror("Listen() error!!");
    exit(0);
  }


  while(1){
    sin_size = sizeof(struct sockaddr_in);
    sock_client = accept(sock,(struct sockaddr*)&client,&sin_size);
    if( sock_client == -1){
      perror("Accept() error!!\n");
      exit(0);
    }

   // Forking Server
   pid = fork();
   switch(pid){
case -1: //khong the tao them chuong trinh con
        printf("can't fork()\n");break;
case 0:
      close(sock);       /* Child Socket Listening ; */
      printf("Have a connection from:%s\n\n",inet_ntoa(client.sin_addr));
      send(sock_client,"\t\tDang nhap he thong!\n\t\tUsername:"******"Username: %s \n" , recv_data);
      //kiem tra username
	recv_data[byte_recv-1] = '\0';
	if(strcmp(recv_data,"conghoan")!=0)
	{
	    send(sock_client,"sai",50,0);//neu sai ten
	    checkuser =-1;
	    }else
	    {
	    send(sock_client,"dung",50,0);//neu dung user
	    checkuser =0;
	    }
	    if(checkuser == -1)
      {
          //send(sock_client,"0",1,0);
          send(sock_client,"\tTai khoan nay chua ton tai, nhap Username => Dang ki\n\t\tUsername:"******"New Username: %s \n" , recv_data);
          send(sock_client,"\tNhap Password => Dang ki\n\t\tPassword:"******"New Password: %s \n" , recv_data);
          send(sock_client,"Dang ki thanh cong",50,0);
	      close(sock_client); /* Close With terminal of Child Socket */
	      break;
      }
      else{
      send(sock_client,"\n\t\tPassword:"******"Password: %s \n" , recv_data);
      //kiem tra password
	recv_data[byte_recv-1] = '\0';
    if(strcmp(recv_data,"conghoan")!=0)
	{
	    send(sock_client,"sai2",50,0);//sai pass
	    checkpass =-1;
	    }else
	    {
	    send(sock_client,"dung2",50,0);//dung pass
	    checkpass = 0;
	    }
      if(checkpass == -1)//neu sai
      {
          //send(sock_client,"Dang nhap khong thanh cong",50,0);
	      close(sock_client); /* Close With terminal of Child Socket */
          break;
      }
      else
{
      //menu chuong trinh
      //send(sock_client,"\t\tWelcome to my server!\n\t\tMenu:\n\t\t1: Ma hoa.\n\t\t2: Giai ma.\n\t\t3: Thoat.",100,0);
   send(sock_client,"\t\tWelcome to my server!\n\t\tMenu:\n\t\t1: Ma hoa.\n\t\t2: Giai ma.\n\t\t3: Thoat.",200,0);
      //while(1)
      //{
	byte_recv = recv(sock_client,recv_data,1024,0);
	recv_data[byte_recv] = '\0';
	if(strcmp(recv_data,"3")==0)
            {
	    close(sock_client); /* Close With terminal of Child Socket */
	    break;
	    }
//=================================giai ma mot file gui toi
	if(recv_data[0]=='2')
	{
	//else{
	    printf("\nClient da chon: %s -- Giai ma\n" , recv_data);
	    //nhan file va luu file
  FILE *pFileluu;
  pFileluu = fopen ("giaima.txt", "wb");
   if ((numbyte = recv(sock_client,recv_data,MAXSIZE,0)) == -1){  /* calls recv() */
    printf("recv() error\n");
    exit(-1);
  }
  printf ("Da nhan -%ld-ki tu", numbyte);
   fwrite(recv_data,1,numbyte,pFileluu);//luu lai file da nhan
   //fclose(pFileluu);
   printf("File tu Client da Upload: \n%s\n",recv_data); /* it prints server's welcome message =) */
   fclose(pFileluu);
        //ma hoa
        DecodeFile(huffmanArray,"giaima.txt","da_giaima.txt");
{
  FILE * pFile;
  FILE *pFile1;
  long lSize;
  char * buffer;
  size_t result;

  int fd, numbytes;	  /* files descriptors */
  char buf[MAXDATASIZE];  /* buf will store received text */
  char buf1[MAXDATASIZE];

  pFile = fopen ("da_giaima.txt", "rb" );
  // pFile1 = fopen ("myfile1.txt", "wb");

  if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

  // obtain file size:
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

  // allocate memory to contain the whole file:
  buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
  if ((numbytes = send (sock_client, buffer, lSize, 0)) == -1){
      printf ("send()error\n");
      exit(-1);
    }
  printf("--%ld ki tu da duoc gui di--\n", lSize);

  printf ("Ket thuc gui\n");
  exit(-1);
//  if ((numbytes=recv(fd,buf,MAXDATASIZE,0)) == -1){  /* calls recv() */
//    printf("recv() error\n");
//    exit(-1);
//  }
       }
	  close(sock_client); /* Close With terminal of Child Socket */
	  break;
	}
//  ----------------------==-=-===================== ma hoa file gui toi
if(recv_data[0]=='1'){
    printf("\nClient da chon: %s -- Ma hoa\n" , recv_data);
	    //nhan file va luu file
  FILE *pFileluu;
  pFileluu = fopen ("mahoa.txt", "wb");
   if ((numbyte = recv(sock_client,recv_data,MAXSIZE,0)) == -1){  /* calls recv() */
    printf("recv() error\n");
    exit(-1);
  }
  printf ("Da nhan -%ld-ki tu", numbyte);
   fwrite(recv_data,1,numbyte,pFileluu);//luu lai file da nhan
   //fclose(pFileluu);
   printf("File tu Client da Upload: \n%s\n",recv_data); /* it prints server's welcome message =) */
   fclose(pFileluu);
        //ma hoa
        huffmanTree = GenerateTreeFromFile("mahoa.txt");
        EncodeFile(huffmanTree,"mahoa.txt","da_mahoa.txt");
        PrintCode(huffmanTree,"bangma.txt");
        FreeHuffmanTree(huffmanTree);     /* free allocated memory */
{
  FILE * pFile;
  FILE *pFile1;
  long lSize;
  char * buffer;
  size_t result;

  int fd, numbytes;	  /* files descriptors */
  char buf[MAXDATASIZE];  /* buf will store received text */
  char buf1[MAXDATASIZE];

  pFile = fopen ("da_mahoa.txt", "rb" );
  // pFile1 = fopen ("myfile1.txt", "wb");

  if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

  // obtain file size:
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

  // allocate memory to contain the whole file:
  buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
  if ((numbytes = send (sock_client, buffer, lSize, 0)) == -1){
      printf ("send()error\n");
      exit(-1);
    }
  printf("--%ld-- ki tu da ma hoa gui ve cho Client--\n", lSize);
  printf ("Ket thuc gui\n");
  exit(-1);
//  if ((numbytes=recv(fd,buf,MAXDATASIZE,0)) == -1){  /* calls recv() */
//    printf("recv() error\n");
//    exit(-1);
//  }
       }
	  close(sock_client); /* Close With terminal of Child Socket */
	  break;
	}
	  }
	}
case 1:
    if(strcmp(recv_data,"3")==0){
      close(sock); /* Close Listening */
      break;
   }
   break;
    }
    }

    close(sock_client); /* Parent Close Connect Socket */
  }
Beispiel #12
0
int main(int argc, char **argv) {
	int retval = 0;
	char *dparams[2];
	int paramc = 0, params = -1;

	char temp[0x1000];
	int done = 0;
	char *source = NULL;
	int n = 0;

	// Acción a realizar
	int action = ACTION_NONE;

	if (argc <= 1) {
		action = ACTION_HELP;
		setparams(0);
	}

	for (n = 1; n <= argc; n++) {
		char *arg;
		arg = (n < argc) ? argv[n] : "";

		//printf("%s\n", arg);

		// Muestra la ayuda y sale
		if (strcmp(arg, "-?") == 0 || strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
			//show_help();
			action = ACTION_HELP;
			setparams(0);
		}

		// Modificadores
		{
			// Modo raw (sin cabeceras de compresión)
			if (strcmp(arg, "-r") == 0 || strcmp(arg, "-raw") == 0) { raw = 1; continue; }

			// Modo silencioso
			if (strcmp(arg, "-s") == 0) { silent = 1; fclose(stdout); continue; }
		}

		// Acciones
		{
			if (arg[0] == '-') {
				int cnt = 1;

				switch (arg[1]) {
					// Codificad
					case 'c': action = ACTION_ENCODE ; setparams(2); break;
					// Decodificia
					case 'd': action = ACTION_DECODE ; setparams(2); break;
					// Comprueba
					case 't': action = ACTION_TEST   ; setparams(1); break;
					// Crea un perfil de compresión
					case 'p': action = ACTION_PROFILE; setparams(1); break;
					// Dumpea el text_buffer inicial
					case 'b': action = ACTION_BDUMP  ; setparams(1); break;
					default:  cnt = 0; break;
				}

				if (cnt) {
					done = 0;
					modifier = (strlen(arg) >= 3) ? atoi(arg + 2) : 3;
					continue;
				}
			}
		}

		if ((n < argc) && (paramc < params)) {
			dparams[paramc++] = arg;
		}

		if (paramc >= params) {
			show_header_once();

			done = 1;
			switch (action) {
				case ACTION_ENCODE:
					if (strcmp(dparams[0], dparams[1]) != 0) {
						retval |= EncodeFile(dparams[0], dparams[1], raw, modifier);
					} else {
						fprintf(stderr, "Can't use same file for input and output\n");
						retval |= -1;
					}
				break;
				case ACTION_DECODE:
					if (strcmp(dparams[0], dparams[1]) != 0) {
						retval |= DecodeFile(dparams[0], dparams[1], raw, modifier);
					} else {
						fprintf(stderr, "Can't use same file for input and output\n");
						retval |= -1;
					}
				break;
				case ACTION_PROFILE:
					if (strlen(arg) < 0x900) {
						sprintf(temp, "%s.profile", arg);
						ProfileStart(temp);
							retval |= DecodeFile(dparams[0], NULL, raw, modifier);
						ProfileEnd();
					}
				break;
				case ACTION_BDUMP:
					DumpTextBuffer(dparams[0]);
				break;
				case ACTION_TEST:
					retval |= CheckCompression(dparams[0], modifier);
				break;
				case ACTION_HELP:
					show_help();
				break;
				default:
					if (n == argc) {
						if (paramc == params || params == 0) exit(retval);
						if (params == -1) show_help();
						fprintf(stderr, "Expected %d params, but %d given\n", params, paramc);
						exit(-1);
					}
					fprintf(stderr, "Unknown parameter '%s'\n", arg);
					exit(-1);
				break;
			}

			paramc = params = 0;
			action = ACTION_NONE;
		}
	}

	show_header_once();

	fprintf(stderr, "Expected %d params, but %d given\n", params, paramc);
	exit(-1);

	return 0;
}