<commit_before>//----------------------------------------------------
// linbc  2014.11.28
// http://linbc.cnblogs.com/
// github: https://github.com/linbc/cocos2dx_xxtea_asset

#include "xxtea.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const char *progname = __FILE__; 

char    *optarg;                /* argument associated with option */
int getopt(int nargc,char * const nargv[],const char *ostr);

const char *_getprogname(void) {
	return progname;
}

static void usage(void) {
	printf("Usage:\n"
		"\n"
		"  %s [-e|-d] file1.lua -o file1.luac -s xxtea -k key -z \n"
		"\n"
		"Options:\n"
		"\n"
		"  -e [lua script|*.jpg]  encode file \n"
		"  -d <lua script|*.jpg>  decode file \n"
		"  -i input file \n"
		"  -o output file \n"
		"  -s set xxteaSign_string \n"
		"  -k set xxtea_key_string \n"
		"  -h                     Show this help message.\n"		
		"",
		progname);
	exit(1);
}

typedef struct opts_holder_t{
	int encode;
	int decode;
	int auto_by_header;

	char input[1024];
	char output[1024];
	char xxteasign[1024];
	char xxteakey[1024];
}opts_holder;

static void parse_opts(opts_holder *cf, int argc, char **argv) {
	int opt;
	int tmp;
	progname = argv[0];	

	memset(cf,0,sizeof(*cf));
	while (-1 != (opt = getopt(argc, argv, "i:o:s:k:aedh"))) {
		switch (opt) {
		case 'e':	cf->encode = 1;	break;
		case 'd':	cf->decode = 1;	break;
		case 'a':	cf->auto_by_header = 1;	break;

		case 'i':	strcpy(cf->input, optarg);	break;
		case 'o':	strcpy(cf->output, optarg);	break;
		case 's':	strcpy(cf->xxteasign, optarg);	break;
		case 'k':	strcpy(cf->xxteakey, optarg);	break;		

		default:
			usage();
		}
	}

	//ܼܡļͷԶģʽȲͬʱ
	tmp = cf->encode + cf->decode + cf->auto_by_header;
	if(tmp > 1 || tmp == 0)
		usage();

	//Ϊ
	if (strlen(cf->input) && strlen(cf->output))
		usage();
}

static int write_file(const char* sign, const char* content, int len, const char* file) {
	int sign_len = 0;	
	FILE *f = fopen(file,"wb");	
	if(!f) {
		printf("open file:%s failed!",file);
		return -1;
	}

	//ʱͲҪļͷָ뼴
	sign_len = sign == NULL? 0 :strlen(sign);
	if(sign_len > 0)
		fwrite(sign,1,sign_len,f);

	fwrite(content, 1, len, f);

	fclose(f);
	return 0;
}

static int read_file(const char* inputf,char **out) {
	char *p = NULL;	
	int total = 0;
	char temp[8096];

	FILE *f = fopen(inputf, "rb");
	if(!f) {
		printf("open file:%s failed!",inputf);
		return -1;
	}

	p = (char*)malloc(1);
	while(!feof(f)){
		int n = fread(temp,1,sizeof(temp),f);
		total += n;
		p = (char*)realloc(p,total + 1);
		memcpy(p + total - n,temp, n);
	}

	fclose(f);<commit_msg>校验参数写错了,导致不能加解密<commit_after>//----------------------------------------------------
// linbc  2014.11.28
// http://linbc.cnblogs.com/
// github: https://github.com/linbc/cocos2dx_xxtea_asset

#include "xxtea.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const char *progname = __FILE__; 

char    *optarg;                /* argument associated with option */
int getopt(int nargc,char * const nargv[],const char *ostr);

const char *_getprogname(void) {
	return progname;
}

static void usage(void) {
	printf("Usage:\n"
		"\n"
		"  %s [-e|-d] file1.lua -o file1.luac -s xxtea -k key -z \n"
		"\n"
		"Options:\n"
		"\n"
		"  -e [lua script|*.jpg]  encode file \n"
		"  -d <lua script|*.jpg>  decode file \n"
		"  -i input file \n"
		"  -o output file \n"
		"  -s set xxteaSign_string \n"
		"  -k set xxtea_key_string \n"
		"  -h                     Show this help message.\n"		
		"",
		progname);
	exit(1);
}

typedef struct opts_holder_t{
	int encode;
	int decode;
	int auto_by_header;

	char input[1024];
	char output[1024];
	char xxteasign[1024];
	char xxteakey[1024];
}opts_holder;

static void parse_opts(opts_holder *cf, int argc, char **argv) {
	int opt;
	int tmp;
	progname = argv[0];	

	memset(cf,0,sizeof(*cf));
	while (-1 != (opt = getopt(argc, argv, "i:o:s:k:aedh"))) {
		switch (opt) {
		case 'e':	cf->encode = 1;	break;
		case 'd':	cf->decode = 1;	break;
		case 'a':	cf->auto_by_header = 1;	break;

		case 'i':	strcpy(cf->input, optarg);	break;
		case 'o':	strcpy(cf->output, optarg);	break;
		case 's':	strcpy(cf->xxteasign, optarg);	break;
		case 'k':	strcpy(cf->xxteakey, optarg);	break;		

		default:
			usage();
		}
	}

	//ܼܡļͷԶģʽȲͬʱ
	tmp = cf->encode + cf->decode + cf->auto_by_header;
	if(tmp > 1 || tmp == 0)
		usage();

	//Ϊ
	if (strlen(cf->input) == 0 || strlen(cf->output) == 0)
		usage();
}

static int write_file(const char* sign, const char* content, int len, const char* file) {
	int sign_len = 0;	
	FILE *f = fopen(file,"wb");	
	if(!f) {
		printf("open file:%s failed!",file);
		return -1;
	}

	//ʱͲҪļͷָ뼴
	sign_len = sign == NULL? 0 :strlen(sign);
	if(sign_len > 0)
		fwrite(sign,1,sign_len,f);

	fwrite(content, 1, len, f);

	fclose(f);
	return 0;
}

static int read_file(const char* inputf,char **out) {
	char *p = NULL;	
	int total = 0;
	char temp[8096];

	FILE *f = fopen(inputf, "rb");
	if(!f) {
		printf("open file:%s failed!",inputf);
		return -1;
	}

	p = (char*)malloc(1);
	while(!feof(f)){
		int n = fread(temp,1,sizeof(temp),f);
		total += n;
		p = (char*)realloc(p,total + 1);
		memcpy(p + total - n,temp, n);
	}

	fclose(f);

	*out = p;
{'fraction_non_alphanumeric': 0.20463320463320464, 'fraction_numerical': 0.020463320463320462, 'mean_word_length': 2.954961832061069, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3977894', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2239, 'n_words': 533}