int main(int argc, char **argv) { Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR); if ( Prog_Arguments_Count() ) { YOYO_BUFFER *bf; byte_t sign[20] = {0}; bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r")); Sha1_Digest(bf->at,bf->count,sign); puts(Str_Hex_Encode(sign,20)); } else { int i, j, buflen; byte_t buf[1000]; int verbose = Prog_Has_Opt("l"); YOYO_SHA1 ctx; for ( i = 0; i < 3; i++ ) { if ( verbose ) printf( " SHA-1 test #%d: ", i + 1 ); Sha1_Start( &ctx ); if ( i == 2 ) { memset( buf, 'a', buflen = 1000 ); for ( j = 0; j < 1000; j++ ) Sha1_Update( &ctx, buf, buflen ); } else Sha1_Update( &ctx,Data_Buf[i], Data_Buflen[i] ); Sha1_Finish( &ctx, buf ); if ( memcmp( buf,Data_Sum[i], 20 ) != 0 ) { if ( verbose ) puts("failed"); return 1; } else { if( verbose ) puts("passed"); } } } return 0; }
int main(int argc, char **argv) { byte_t buf[256]; int i, verbose, buflen; YOYO_HMAC_SHA2 ctx; Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR); verbose = Prog_Has_Opt("l"); for( i = 0; i < 7; i++ ) { if( verbose ) printf( " HMAC-SHA-2 test #%d: ", i + 1 ); if( i == 5 || i == 6 ) { memset( buf, '\xAA', buflen = 131 ); Hmac_Sha2_Start( &ctx, buf, buflen ); } else Hmac_Sha2_Start( &ctx, Data_Key[i], Data_Keylen[i] ); Hmac_Sha2_Update( &ctx, Data_Buf[i], Data_Buflen[i] ); Hmac_Sha2_Finish( &ctx, buf ); buflen = ( i == 4 ) ? 16 : 32; if( memcmp( buf, Data_Sum[i], buflen ) != 0 ) { if( verbose ) puts("failed"); return 1; } else { if( verbose ) puts("passed"); } } return 0; }
int main(int argc, char **argv) { Prog_Init(argc,argv,0,0); }
int main(int argc, char **argv) { void *f; int logout; clock_t S = clock(); clock_t S0 = 0, S1; Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR); logout = Prog_Has_Opt("l"); f = Cfile_Open(Prog_Argument_Dflt(0,"longinteger.txt"),"r"); while ( !Oj_Eof(f) ) __Auto_Release { YOYO_BIGINT *a, *b, *c, *R; char *l = Oj_Read_Line(f); YOYO_ARRAY *q = Str_Split(l,0); if ( !q->count ) continue; a = Bigint_Decode_10(q->at[1]); b = Bigint_Decode_10(q->at[2]); c = Bigint_Decode_10(q->at[3]); R = Bigint_Decode_10(q->at[4]); if ( !strcmp(q->at[0],"*") ) { YOYO_BIGINT *Q = Bigint_Mul(Bigint_Copy(a),b); if (logout) puts(__Format("%s*%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"/") ) { YOYO_BIGINT *Q = Bigint_Div(Bigint_Copy(a),b); if (logout) puts(__Format("%s/%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"+") ) { YOYO_BIGINT *Q = Bigint_Add(Bigint_Copy(a),b); if (logout) puts(__Format("%s+%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"-") ) { YOYO_BIGINT *Q = Bigint_Sub(Bigint_Copy(a),b); if (logout) puts(__Format("%s-%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"%") ) { YOYO_BIGINT *Q = Bigint_Modulo(Bigint_Copy(a),b); if (logout) puts(__Format("%s%%%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"**%") ) { YOYO_BIGINT *Q = Bigint_Expmod(Bigint_Copy(a),b,c); if (logout) puts(__Format("%s**%s%%%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(c), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"*%") ) { YOYO_BIGINT *Q = Bigint_Modmul(Bigint_Copy(a),b,c); if (logout) puts(__Format("%s*%s%%%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(c), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"*/%") ) { YOYO_BIGINT *Q = Bigint_Invmod(Bigint_Copy(a),b); if (logout) puts(__Format("%s/%%%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],"<<") ) { YOYO_BIGINT *Q = Bigint_Lshift(Bigint_Copy(a),b->value[0]); if (logout) puts(__Format("%s<<%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } else if ( !strcmp(q->at[0],">>") ) { YOYO_BIGINT *Q = Bigint_Rshift(Bigint_Copy(a),b->value[0]); if (logout) puts(__Format("%s>>%s=%s (%s)", Bigint_Encode_10(a), Bigint_Encode_10(b), Bigint_Encode_10(Q), Bigint_Encode_10(R))); REQUIRE( Bigint_Equal(Q,R) ); } } S1 = clock(); printf("total time: %.3f\n",(double)(S1-S)/CLOCKS_PER_SEC); return 0; }
////////////////////////////////////////////////////////////////////////////// //WINMAIN ////////////////////////////////////////////////////////////////////////////// int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { //assign instance to global variable hInstMain=hInstance; //create window class WNDCLASSEX wcx; //set the size of the structure wcx.cbSize=sizeof(WNDCLASSEX); //class style wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; //window procedure wcx.lpfnWndProc=TheWindowProc; //class extra wcx.cbClsExtra=0; //window extra wcx.cbWndExtra=0; //application handle wcx.hInstance=hInstMain; //icon wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION); //cursor wcx.hCursor=LoadCursor(NULL,IDC_ARROW); //background color wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); //menu wcx.lpszMenuName=NULL; //class name wcx.lpszClassName=WINDOWCLASS; //small icon wcx.hIconSm=NULL; //register the window class, return 0 if not successful if(!RegisterClassEx(&wcx)) return(0); //create main window hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_POPUP | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL); //error check if(!hWndMain) return(0); //if program initialization failed, then return with 0 if(!Prog_Init()) return(0); //message structure MSG msg; //message pump for(;;) { //look for a message if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { //there is a message //check that we arent quitting if(msg.message==WM_QUIT) break; //translate message TranslateMessage(&msg); //dispatch message DispatchMessage(&msg); } //run main game loop Prog_Loop(); } //clean up program data Prog_Done(); //return the wparam from the WM_QUIT message return(msg.wParam); }