示例#1
0
文件: lstrlib.c 项目: guodawei/lua
static int arith (lua_State *L, int op, const char *mtname) {
  if (tonum(L, 1) && tonum(L, 2))
    lua_arith(L, op);  /* result will be on the top */
  else
    trymt(L, mtname);
  return 1;
}
int sub_byte(char index[][three], int subbyteround){
	int count=0, i, j;
  	int a, b;
  	char numbersub[3];
  	//printf("subbyte value:\n");
  	if(subbyteround==0){
  		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				a = tonum(index[count][0]);
				b = tonum(index[count][1]);
				//printf("%d %d %d\n", a, b, s_box[a][b]);
				matrix[j][i] = s_box[a][b];
				secondmatrix[j][i] = s_box[a][b];
				count++;
			}
		}
  	}
  	else{
  		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				sprintf(numbersub, "%x", matrix[j][i]);
				a = tonum(numbersub[0]);
				b = tonum(numbersub[1]);
				//printf("%d %d\n", a, b);
				//printf("%d %d %d\n", a, b, s_box[a][b]);
				matrix[j][i] = s_box[a][b];
				secondmatrix[j][i] = s_box[a][b];
			}
		}
  	}
	
}
int sub_roundkey(int matrixkey[][four]){
	int i, ans1, ans2;
	char b[3], a[3];
	for(i=0; i<4; i++){
		sprintf(a, "%x", matrixkey[i][3]);
		ans1 = tonum(a[0]);
		ans2 = tonum(a[1]);
		nextmatrixkey[i][0] = s_box[ans1][ans2];
	}
}
int sub_byte_key(char indexkey[][three]){
	int count=0, i, j;
  	int a, b;
  	//printf("subbyte value key:\n");
	for(i=0; i<4; i++){
		for(j=0; j<4; j++){
			a = tonum(indexkey[count][0]);
			b = tonum(indexkey[count][1]);
			//printf("%d %d %d\n", a, b, s_box[a][b]);
			matrixkey[j][i] = manual_box[a][b];
			copykey[j][i] = manual_box[a][b];
			count++;
		}
	}
}
int sub_byte(char index[][three]){
	int count=0, i, j;
  	int a, b;
  	//printf("subbyte value:\n");
	for(i=0; i<4; i++){
		for(j=0; j<4; j++){
			a = tonum(index[count][0]);
			b = tonum(index[count][1]);
			//printf("%d %d %d\n", a, b, s_box[a][b]);
			matrix[j][i] = s_box[a][b];
			secondmatrix[j][i] = s_box[a][b];
			count++;
		}
	}
}
示例#6
0
/* decode reference position -------------------------------------------------*/
static void decode_refpos(char *buff, const solopt_t *opt, double *rb)
{
    double val[MAXFIELD],pos[3];
    int i,n;
    const char *sep=opt2sep(opt);
    
    trace(3,"decode_refpos: buff=%s\n",buff);
    
    if ((n=tonum(buff,sep,val))<3) return;
    
	if ((opt->posf==SOLF_XYZ) || (opt->posf==SOLF_RVA)) { /* xyz */
        for (i=0;i<3;i++) rb[i]=val[i];
    }
    else if (opt->degf==0) { /* lat/lon/hgt (ddd.ddd) */
        pos[0]=val[0]*D2R;
        pos[1]=val[1]*D2R;
        pos[2]=val[2];
        pos2ecef(pos,rb);
    }
    else if (opt->degf==1&&n>=7) { /* lat/lon/hgt (ddd mm ss) */
        pos[0]=dms2deg(val  )*D2R;
        pos[1]=dms2deg(val+3)*D2R;
        pos[2]=val[6];
        pos2ecef(pos,rb);
    }
}
示例#7
0
/* decode e/n/u-baseline -----------------------------------------------------*/
static int decode_solenu(char *buff, const solopt_t *opt, sol_t *sol)
{
    double val[MAXFIELD],Q[9]={0};
    int i=0,j,n;
    const char *sep=opt2sep(opt);
    
    trace(4,"decode_solenu:\n");
    
    if ((n=tonum(buff,sep,val))<3) return 0;
    
    for (j=0;j<3;j++) {
        sol->rr[j]=val[i++]; /* enu */
    }
    if (i<n) sol->stat=(unsigned char)val[i++];
    if (i<n) sol->ns  =(unsigned char)val[i++];
    if (i+3<n) {
        Q[0]=val[i]*val[i]; i++; /* sde */
        Q[4]=val[i]*val[i]; i++; /* sdn */
        Q[8]=val[i]*val[i]; i++; /* sdu */
        if (i+3<n) {
            Q[1]=Q[3]=NSQR(val[i]); i++; /* sden */
            Q[5]=Q[7]=NSQR(val[i]); i++; /* sdnu */
            Q[2]=Q[6]=NSQR(val[i]); i++; /* sdue */
        }
		covtosol(Q,sol->qr);
    }
    if (i<n) sol->age  =(float)val[i++];
    if (i<n) sol->ratio=(float)val[i];
    
    sol->type=1; /* postion type = enu */
    sol->rva=0; /* postion type != rva */

    if (MAXSOLQ<sol->stat) sol->stat=SOLQ_NONE;
    return 1;
}
示例#8
0
/* decode x/y/z-ecef ---------------------------------------------------------*/
static int decode_solxyz(char *buff, const solopt_t *opt, sol_t *sol)
{
    double val[MAXFIELD],P[9]={0};
    int i=0,j,n;
    const char *sep=opt2sep(opt);
    
    trace(4,"decode_solxyz:\n");
    
    if ((n=tonum(buff,sep,val))<3) return 0;
    
    for (j=0;j<3;j++) {
        sol->rr[j]=val[i++]; /* xyz */
    }
    if (i<n) sol->stat=(unsigned char)val[i++];
    if (i<n) sol->ns  =(unsigned char)val[i++];
	if (i+3<n) {
		P[0]=val[i]*val[i]; i++; /* sdx */
        P[4]=val[i]*val[i]; i++; /* sdy */
		P[8]=val[i]*val[i]; i++; /* sdz */
        if (i+3<n) {
            P[1]=P[3]=NSQR(val[i]); i++; /* sdxy */
            P[5]=P[7]=NSQR(val[i]); i++; /* sdyz */
            P[2]=P[6]=NSQR(val[i]); i++; /* sdzx */
        }
		covtosol(P,sol->qr);
    }
	if (i<n) sol->age  =(float)val[i++];
    if (i<n) sol->ratio=(float)val[i];
    
	sol->type=0; /* postion type = xyz */
	sol->rva=0; /* postion type != rva */
    
    if (MAXSOLQ<sol->stat) sol->stat=SOLQ_NONE;
    return 1;
}
示例#9
0
int
main()
{
	int prod, max = 0, index, i;
	char *a = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";

	for (i = 0; i < 996; i++) {
		prod = tonum(a[i]) * tonum(a[i+1]) * tonum(a[i+2]) * tonum(a[i+3]) * tonum(a[i+4]);
		if (prod > max) {
			max = prod;
			index = i;
		}
	}
	printf("max product - %d, at index - %d\n", max, index);

	return (0);
}
示例#10
0
文件: 4854.cpp 项目: dk00/old-stuff
main() {
  int T, C = 1;
  scanf("%d", &T);
  while (T--) {
    int i, j, a, b, c, d;
    for (i = 0; i < 5; ++i)
      for (j = 0; j < 90; ++j)
        p2[i][j] = p3[i][j] = p1[i][j];
    for (i = a = b = 0; i < 8; ++i) {
      scanf("%s", tmp[i]);
      for (j = 0; tmp[i][j]; ++j) {
        if (j < 9) a += tonum(tmp[i][j]);
        else b += tonum(tmp[i][j]);
        if ('A' <= tmp[i][j] && tmp[i][j] <= 'Z') {
          if (j < 9) p2[3][j] = tmp[i][j];
          else p3[3][j-10] = tmp[i][j];
        }
        if (tmp[i][j] == '_') {
          if (j < 9) c = i - 4;
          else d = i - 4;
        }
      }
    }
    printf("Case %d:\n", C++);
    for (i = 0; i < 8; ++i)
      for (j = 0; j < 90; ++j)
        tmp[i][j] = p0[i][j];
    if (a > b) a = 2, b = 0;
    else if (a == b) a = b = 1;
    else a = 0, b = 2;
    if (a == c && b == d) {
      puts("The figure is correct.");
      continue;
    }
    for (i = 0; i < 5; ++i)
      for (j = 0; j < 8; ++j)
        tmp[i+a][j] = p2[i][j];
    for (i = 0; i < 5; ++i)
      for (j = 0; j < 8; ++j)
        tmp[i+b][j+10] = p3[i][j];
    for (i = 0; i < 7; ++i)
      puts(tmp[i]);
  }
}
示例#11
0
void savetext(strings s[], int i, const char * const line)
{	const char *p;
	char *q;

	if(i > maxNr)
		maxNr = i;

	free(s[i].text);
	if((q = s[i].text = malloc(strlen(p = line) + 1)) == NULL) {
		fputs("Out of memory\n", stderr);
		exit(85);
	}
	/* Check  and compact the string */
	while(isspace(*p)) ++p;
	while(*p) {
		if(*p == '%') {
			switch(*++p) {
			case '%': break;		/* expands to single '%' */
			case '\0': --p; break;	/* dito */
			case '.': 		/* ignore completely */
				++p;
				continue;
			case '&':		/* hexa-decimal string */
				if(isxdigit(p[1]) && isxdigit(p[2])) {
					*q++ = (tonum(p[1]) << 4) | tonum(p[2]);
					p += 3;
					continue;
				}
				/** fall though **/
			case '1': case '2': case '3': case 'A':
				/* Leave both in the string */
				*q++ = '%';
				break;
			}
		}
		*q++ = *p++;
	}
	*q++ = '\0';
}
示例#12
0
/* decode gsi f solution -----------------------------------------------------*/
static int decode_solgsi(char *buff, const solopt_t *opt, sol_t *sol)
{
    double val[MAXFIELD];
    int i=0,j;
    
    trace(4,"decode_solgsi:\n");
    
    if (tonum(buff," ",val)<3) return 0;
    
    for (j=0;j<3;j++) {
        sol->rr[j]=val[i++]; /* xyz */
    }
    sol->stat=SOLQ_FIX;
    return 1;
}
示例#13
0
文件: 05fin5.c 项目: dk00/old-stuff
main()
{
    int y,m,d,T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d %d %d",&y,&m,&d);
        if(y<2000)goto no;
        if(m<1 || m>12)goto no;
        m0[2]=28+(y%400==0 ||(y%100 && y%4==0));
        if(d<1 || d>m0[m])goto no;
        puts(w[tonum(y,m,d)]);
        continue;
    no: puts("invalid date");
    }
}
示例#14
0
/* decode lat/lon/height -----------------------------------------------------*/
static int decode_solllh(char *buff, const solopt_t *opt, sol_t *sol)
{
    double val[MAXFIELD],pos[3],Q[9]={0},P[9];
    int i=0,n;
    const char *sep=opt2sep(opt);
    
    trace(4,"decode_solllh:\n");
    
    n=tonum(buff,sep,val);
    
    if (!opt->degf) {
        if (n<3) return 0;
        pos[0]=val[i++]*D2R; /* lat/lon/hgt (ddd.ddd) */
        pos[1]=val[i++]*D2R;
        pos[2]=val[i++];
    }
    else {
        if (n<7) return 0;
        pos[0]=dms2deg(val  )*D2R; /* lat/lon/hgt (ddd mm ss) */
        pos[1]=dms2deg(val+3)*D2R;
        pos[2]=val[6];
        i+=7;
    }
    pos2ecef(pos,sol->rr);
    if (i<n) sol->stat=(unsigned char)val[i++];
    if (i<n) sol->ns  =(unsigned char)val[i++];
    if (i+3<n) {
        Q[4]=val[i]*val[i]; i++; /* sdn */
        Q[0]=val[i]*val[i]; i++; /* sde */
        Q[8]=val[i]*val[i]; i++; /* sdu */
        if (i+3<n) {
            Q[1]=Q[3]=NSQR(val[i]); i++; /* sdne */
            Q[2]=Q[6]=NSQR(val[i]); i++; /* sdeu */
			Q[5]=Q[7]=NSQR(val[i]); i++; /* sdun */
		}
		covecef(pos,Q,P);
		covtosol(P,sol->qr);
    }
    if (i<n) sol->age  =(float)val[i++];
    if (i<n) sol->ratio=(float)val[i];
    
    sol->type=0; /* postion type = xyz */
    sol->rva=0; /* postion type != rva */

    if (MAXSOLQ<sol->stat) sol->stat=SOLQ_NONE;
    return 1;
}
示例#15
0
文件: dwterm.c 项目: 8l/FUZIX
/* Send a char to the console, processing for ANSI/TELNET chars */
void charout( char c ){
	static char mode=0;
	int i;

	switch( mode ){
		/* normal mode */
	case 0: 
		if( c == 255 ){
			mode=3;
			return;
		}
		if( c != ESC ) 	write( 1, &c ,1 );
		else{ 
			mode=1;
		}
		return;
		/* ESC detected */
	case 1:
		if( c=='[' ){
			mode=2;
			return;
		}
		return;
		/* Multi-byte detected */
	case 2: 
		if( isnum(c) ){
			para[no]=para[no]*10+tonum(c);
			return;
		}
		if( c == ';' ){
			no++;
			return;
		}
		no++;
		goto final;
		/* Telnet IAC detected */
	case 3:
		switch( c ){
		case 255:
			write(1,&c,1);
			mode=0;
			return;

		case 251:
			mode=5;
			return;
		case 252:
			mode=6;
			return;
		case 253:
		case 254:
			if(hex) printf("<IAC><%x>",c);
			mode=4;
			return;
		}
		mode=0;
		return;
		/* send Telnet's WILLNOTs to server */
	case 4:
		if( hex )printf("<%x>\n", c );
		write( fddw, "\xff\xfc",2);
		write( fddw, &c, 1 );
		mode = 0;
		return;
		/* received a WILL */
	case 5:
		if( c == 1 ){
			lecho = 0;
			//write(fddw,"\xff\xfd",2);
			//write(fddw, &c, 1 );
			mode = 0;
			return;
		}
		write( fddw,"\xff\xfe",2);
		write( fddw, &c, 1);
		mode = 0;
		return;
		/* received a WONT */
	case 6:
		if( hex ) printf("opt<%x>\n", c );
		if( c == 1 ) lecho = -1;
		else{
			write( fddw, "\xff\xfe", 2 );
			write( fddw, &c, 1 );
		}
		mode = 0;
		return;

	}
	/* and the trailing command */
 final:
	//	printf("DEBUG: %d %d %d %c\n", para[0], para[1], para[2], c);
	switch( c ){
示例#16
0
文件: string.c 项目: cdngeo/simgear
int naStr_parsenum(char* str, int len, double* result)
{
    return tonum((unsigned char*)str, len, result);
}
示例#17
0
文件: string.c 项目: cdngeo/simgear
int naStr_numeric(naRef str)
{
    double dummy;
    return tonum(DATA(PTR(str).str), LEN(PTR(str).str), &dummy);
}
示例#18
0
文件: string.c 项目: cdngeo/simgear
int naStr_tonum(naRef str, double* out)
{
    return tonum(DATA(PTR(str).str), LEN(PTR(str).str), out);
}
int main(){
	int rounds, i, j, count, numberround, answer, rconround = 0, subbyteround = 0;;
	char plaintext[17] = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
	char key[17] = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
	char index[16][3];
	char indexkey[16][3];
	char b[3], a[3];
	printf("Input Text: ");
	gets(plaintext);
	printf("Input Key: ");
	scanf(" %[^\n]s\n", key);
	rounds = ceil(strlen(plaintext)/16);
	for(i=0; i<16; i++){
		sprintf(a, "%x", plaintext[i]); /* keep char ascii to hex base */
		sprintf(b, "%x", key[i]);
		strcpy(index[i], a);
		strcpy(indexkey[i], b);
		//printf("%x\n", index[i]);
		//printf("%s\n", indexkey[i]);
	}
	for(i=0; i<16; i++){//we do add round key first before do 10 loop
			//printf("%d\n", (((tonum(index[i][0]))*10)+(tonum(index[i][1]))));
			answer = (((tonum(index[i][0]))*10)+(tonum(index[i][1])))^(((tonum(indexkey[i][0]))*10)+(tonum(indexkey[i][1])));
			printf("%d\n", answer);
			sprintf(a, "%x", answer);
			printf("%s\n", a);
			strcpy(index[i], a);
			//printf("%s\n", index[i]);
	}
	for(numberround=1; numberround<=10; numberround++){
		printf("%d %d\n", rconround,subbyteround);
		if(numberround==1){
			sub_byte_key(indexkey);
			roundkey(matrixkey, rconround);
		}
		else{
			roundkey(matrixkey, rconround);
		}
		sub_byte(index, subbyteround);
		printf("roundkey:\n");
		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				printf("%x ", matrixkey[i][j]);
			}
			printf("\n");
		}
		printf("-------------------------------------------\n");
		printf("Subbyte:\n");
		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				printf("%x ", matrix[i][j]);
			}
			printf("\n");
		}
		printf("-------------------------------------------\n");
		shiftrow();
		printf("shiftrow value:\n");
		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				printf("%x ", matrix[i][j]);
			}
			printf("\n");
		}
		printf("-------------------------------------------\n");
		if(numberround<10){
			mixcolumn();
			printf("mixcolumn value:\n");
			for(i=0; i<4; i++){
				for(j=0; j<4; j++){
					printf("%x ", matrix[i][j]);
				}
				printf("\n");
			}
		}
		printf("-------------------------------------------\n");
		addroundkey();
		printf("Addroundkey value:\n");
		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				printf("%c", matrix[j][i]);
			}
			//printf("\n");
		}
		printf("\n");
		subbyteround++;
		rconround++;
	}

}	
示例#20
0
int naStr_numeric(naRef str)
{
    double dummy;
    return tonum(str.ref.ptr.str->data, str.ref.ptr.str->len, &dummy);
}
示例#21
0
int naStr_tonum(naRef str, double* out)
{
    return tonum(str.ref.ptr.str->data, str.ref.ptr.str->len, out);
}