示例#1
0
void main()
{
	initkey();
	while(1)
	{
		Mission1();
		Mission2();
	}
}
示例#2
0
char* jhencrypt(const char* oristr){
	AES_KEY aes;
	unsigned char* input_string = NULL;
	unsigned char* encrypt_string = NULL;
	char* out_string = NULL;
	int i;
    // set the encryption length
    int len = strlen(oristr)+1;
	int t = len/AES_BLOCK_SIZE;
	int m = len%AES_BLOCK_SIZE;
	if(0!=m) len = (t+1)*AES_BLOCK_SIZE;

	if(initkey()<0) return NULL;

	    // set the input string
    input_string = (unsigned char*)calloc(len, sizeof(unsigned char));
	encrypt_string = (unsigned char*)calloc(len, sizeof(unsigned char)); 
	out_string = (char*)calloc(len*2+1, sizeof(unsigned char)); 

	strncpy((char*)input_string, oristr, strlen(oristr));

	if (AES_set_encrypt_key(rkey, 128, &aes) < 0) {
        fprintf(stderr, "error: Unable to set encryption key in AES\n");
		if(NULL != input_string) free(input_string); 
		if(NULL != encrypt_string) free(encrypt_string); 
		if(NULL != out_string) free(out_string); 
        return NULL;
    }

    // encrypt (iv will change)
    AES_cbc_encrypt(input_string, encrypt_string, len, &aes, riv, AES_ENCRYPT);
	
	// conver encrypted string to hexadecimal number string 
	for (i=0; i<len; ++i) {
		char xchar[3]={0};
		sprintf(xchar,"%02x",encrypt_string[i]);
		strcat(out_string, xchar);
	}

	if(NULL != input_string) free(input_string); 
	if(NULL != encrypt_string) free(encrypt_string); 
	
	return out_string;
}
示例#3
0
char* jhdecrypt(const char* encryptedStr){
	AES_KEY aes;
	unsigned char* decrypt_string;
	unsigned char* rencstr;
	int len=strlen(encryptedStr);
	int i;
	if(len%2 !=0 ) {
		fprintf(stderr, "error: Invalid encrypted string.\n");
		return NULL;
	}

	if(initkey()<0) return NULL;

	rencstr=(unsigned char*)calloc(len/2, sizeof(unsigned char));

	// conver hexadecimal number string to encrypted string
	for(i=0;i<len;i+=2){
		char xchar[3]={0};
		xchar[0]=encryptedStr[i];
		xchar[1]=encryptedStr[i+1];
		int nValude = 0;       
		sscanf(xchar,"%x",&nValude);  
		rencstr[i/2]=nValude;
	}

	decrypt_string = (unsigned char*)calloc(len/2, sizeof(unsigned char));

	if (AES_set_decrypt_key(rkey, 128, &aes) < 0) {
        fprintf(stderr, "Unable to set decryption key in AES\n");
		if(NULL != rencstr) free(rencstr); 
		if(NULL != decrypt_string) free(decrypt_string); 
        return NULL;
    }

    // decrypt notice rencstr'length is len/2
    AES_cbc_encrypt(rencstr, decrypt_string, len/2, &aes, riv, AES_DECRYPT);
	return (char*)decrypt_string;
}
示例#4
0
int
main(int argc, char **argv)
{
	int ch;
	int k, retcode;

	infile = stdin;
	diagfile = stderr;
#if 1 /* RAGGE */
	char file[] = "/tmp/initfile.XXXXXX";
	char buf[100];
	close(mkstemp(file));
	sprintf(buf, "sort > %s", file);
	initfile = popen(buf, "w");
#endif


#define DONE(c)	{ retcode = c; goto finis; }

	while ((ch = getopt(argc, argv, "qw:UuOdpC1I:Z:X:")) != -1)
		switch (ch) {
		case 'q':
			quietflag = YES;
			break;

		case 'w':
			if(optarg[0]=='6' && optarg[1]=='6') {
				ftn66flag = YES;
			} else
				nowarnflag = YES;
			break;

		case 'U':
			shiftcase = NO;
			break;

		case 'u':
			undeftype = YES;
			break;

		case 'O':
			optimflag = YES;
#ifdef notyet
			xdeljumps = 1;
			xtemps = 1;
#endif
			break;

		case 'd':
			debugflag = YES;
			break;

		case 'p':
			profileflag = YES;
			break;

		case 'C':
			checksubs = YES;
			break;

		case '1':
			onetripflag = YES;
			break;

		case 'I':
			if(*optarg == '2')
				tyint = TYSHORT;
			else if(*optarg == '4') {
				shortsubs = NO;
				tyint = TYLONG;
			} else if(*optarg == 's')
				shortsubs = YES;
			else
				fatal1("invalid flag -I%c\n", *optarg);
			tylogical = tyint;
			break;

		case 'Z':	/* pass2 debugging */
			while (*optarg)
				switch (*optarg++) {
				case 'b': /* basic block and SSA building */
					++b2debug;
					break;
				case 'c': /* code printout */
					++c2debug;
					break;
				case 'e': /* print tree upon pass2 enter */
					++e2debug;
					break;
				case 'f': /* instruction matching */
					++f2debug;
					break;
				case 'g':
					++g2debug;
					break;
				case 'n':
					++ndebug;
					break;
				case 'o':
					++o2debug;
					break;
				case 'r': /* register alloc/graph coloring */
					++r2debug;
					break;
				case 's': /* shape matching */
					++s2debug;
					break;
				case 't':
					++t2debug;
					break;
				case 'u': /* Sethi-Ullman debugging */
					++u2debug;
					break;
				case 'x':
					++x2debug;
					break;
				default:
					fprintf(stderr, "unknown Z flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
			break;

		case 'X':	/* pass1 debugging */
			while (*optarg)
				switch (*optarg++) {
				case 'm': /* memory allocation */
					++mflag;
					break;
				case 't': /* tree debugging */
					tflag++;
					break;
				default:
					usage();
				}
			break;

		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	mkdope();
	initkey();
	if (argc > 0) {
		if (inilex(copys(argv[0])))
			DONE(1);
		if (!quietflag)
			fprintf(diagfile, "%s:\n", argv[0]);
		if (argc != 1)
			if (freopen(argv[1], "w", stdout) == NULL) {
				fprintf(stderr, "open output file '%s':",
				    argv[1]);
				perror(NULL);
				exit(1);
			}
	} else {
		inilex(copys(""));
	}
	fileinit();
	procinit();
	if((k = yyparse())) {
		fprintf(diagfile, "Bad parse, return code %d\n", k);
		DONE(1);
	}
	if(nerr > 0)
		DONE(1);
	if(parstate != OUTSIDE) {
		warn("missing END statement");
		endproc();
	}
	doext();
	preven(ALIDOUBLE);
	prtail();
	puteof();
	DONE(0);


finis:
	pclose(initfile);
	retcode |= dodata(file);
	unlink(file);
	done(retcode);
	return(retcode);
}