コード例 #1
0
ファイル: s3c6.c プロジェクト: miqueljubert/matasanocrypto
int main( int argc, char *argv[] )
{
    mtrng_t mt;
    srand(42);
    //Wait for a random time
    printf("Sleeping...\n");
    sleep( (rand()%1000) + 40);
    int seed = time(NULL);
    SeedMT( &mt, seed );
    printf("Seeded...\n");
    printf("Sleeping...\n");
    sleep( (rand()%1000) + 40);
    printf("Woke up!...\n");
    uint32_t first = ExtractNumber( &mt );

    int i;
    int currTime = time(NULL);
    mtrng_t temp;
    for( i = 0; i < 100000; i++ ){
        SeedMT( &temp, currTime );
        uint32_t num = ExtractNumber( &temp ) ;
        if( num == first ) {
            printf("FOUND:%d\n", currTime );
            printf("Used Seed:%d\n", seed );
            break;
        }
        currTime--;
    }
    return 0;
}
コード例 #2
0
ファイル: s3c8.c プロジェクト: miqueljubert/matasanocrypto
int main( int argc, char *argv[] )
{
    srand(time(NULL));

    int size = ( rand()%300 ) + 100;
    uint16_t s16 = rand()%0x10000;
    printf("Seed:%d\n",s16);

    byte_t *buffer = malloc(size);
    int i;
    for( i = 0; i < size-14; i++ ) {
        buffer[i] = rand();
    }
    for( ; i < size; i++ ) {
        buffer[i] = 'A';
    }
    buffer[i] = '\0';

    for( i = 0; i < size; i++ ) printf("%02x",buffer[i]);
    printf("\n");

    EncodePRNG( s16, buffer, size );
    
    for( i = 0; i < size; i++ ) printf("%02x",buffer[i]);
    printf("\n");
    
    uint16_t nseed;
    
    mtrng_t mt2;
    for( i = 0; i < 0x10000; i++ ) {
        SeedMT( &mt2, i);
        int j;
        int ding = 0;
        for( j = 0; j < size; j++ ) {
            if( j < (size-14) ) {
                ExtractNumber( &mt2 );
            } else {
                if( ((ExtractNumber( &mt2 )%256) ^ buffer[j] ) == 'A' ) {
                    ding++;
                }
            }
        }
        if( ding == 14 ) {
            printf("dingnumber:%d %d\n",ding,i);
            nseed = i;
        }
    }

    EncodePRNG( nseed, buffer, size );
    for( i = 0; i < size; i++ ) printf("%02x",buffer[i]);
    printf("\n");

    return 0;
}
コード例 #3
0
RandomNumberGrabber::RandomNumberGrabber(char* filename)
{
    m_input_file = filename;
    stream.open(filename); 
    total_numbers = ExtractNumber();
    ofc = 0;

    for (int i = 0; i < total_numbers; i++)
    {
        random_numbers.push_back(ExtractNumber());
    }
}
コード例 #4
0
//++ ------------------------------------------------------------------------------------
// Details: Parse the command's argument options string and try to extract the value *this
//          argument is looking for.
// Type:    Overridden.
// Args:    vwArgContext    - (RW) The command's argument options string.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMICmdArgValThreadGrp::Validate(CMICmdArgContext &vwArgContext)
{
    if (vwArgContext.IsEmpty())
        return m_bMandatory ? MIstatus::failure : MIstatus::success;

    if (vwArgContext.GetNumberArgsPresent() == 1)
    {
        const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
        if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
        {
            m_bFound = true;
            m_bValid = true;
            m_argValue = GetNumber();
            vwArgContext.RemoveArg(rArg);
            return MIstatus::success;
        }
        else
            return MIstatus::failure;
    }

    // More than one option...
    const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString &rArg(*it);
        if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
        {
            m_bFound = true;

            if (vwArgContext.RemoveArg(rArg))
            {
                m_bValid = true;
                m_argValue = GetNumber();
                return MIstatus::success;
            }
            else
                return MIstatus::failure;
        }

        // Next
        ++it;
    }

    return MIstatus::failure;
}
コード例 #5
0
ファイル: s3c8.c プロジェクト: miqueljubert/matasanocrypto
void EncodePRNG( uint16_t seed, byte_t *data, int size )
{
    mtrng_t mt;
    SeedMT( &mt, seed );

    int i;
    for( i = 0; i < size; i++ ) {
        byte_t num = ExtractNumber( &mt )%256;
        data[i] = data[i] ^ num;
    }
}
コード例 #6
0
ファイル: img2srec.c プロジェクト: AvalueAES/rev-sa01
int main( int argc, char *argv[ ])
{
  DWORD offset;

  if (argc == 2) {
    ConvertELF(argv[1], 0);
  } /* if */
  else if ((argc == 4) && (strcmp(argv[1], "-o") == 0)) {
    ExtractNumber(&offset, argv[2]);
    ConvertELF(argv[3], offset);
  } /* if */
  else {
    fprintf (stderr, "Usage: img2srec [-o offset] <image>\n");
  } /* if */

  return 0;
} /* main */
コード例 #7
0
ファイル: pdf.cpp プロジェクト: june-y/pdf_parse
//This method processes an uncompressed Adobe (text) object and extracts text.
void ProcessOutput(FILE* file, char* output, size_t len)
{
	//Are we currently inside a text object?
	bool intextobject = false;

	//Is the next character literal (e.g. \\ to get a \ character or \( to get ( ):
	bool nextliteral = false;
	
	//() Bracket nesting level. Text appears inside ()
	int rbdepth = 0;

	//Keep previous chars to get extract numbers etc.:
	char oc[oldchar];
	int j=0;
	for (j=0; j<oldchar; j++) oc[j]=' ';

	for (size_t i=0; i<len; i++)
	{
		char c = output[i];
		if (intextobject)
		{
			if (rbdepth==0 && seen2("TD", oc))
			{
				//Positioning.
				//See if a new line has to start or just a tab:
				float num = ExtractNumber(oc,oldchar-5);
				if (num>1.0)
				{
					fputc(0x0d, file);
					fputc(0x0a, file);
				}
				if (num<1.0)
				{
					fputc('\t', file);
				}
			}
			if (rbdepth==0 && seen2("ET", oc))
			{
				//End of a text object, also go to a new line.
				intextobject = false;
				fputc(0x0d, file);
				fputc(0x0a, file);
			}
			else if (c=='(' && rbdepth==0 && !nextliteral) 
			{
				//Start outputting text!
				rbdepth=1;
				//See if a space or tab (>1000) is called for by looking
				//at the number in front of (
				int num = ExtractNumber(oc,oldchar-1);
				if (num>0)
				{
					if (num>1000.0)
					{
						fputc('\t', file);
					}
					else if (num>100.0)
					{
						fputc(' ', file);
					}
				}
			}
			else if (c==')' && rbdepth==1 && !nextliteral) 
			{
				//Stop outputting text
				rbdepth=0;
			}
			else if (rbdepth==1) 
			{
				//Just a normal text character:
				if (c=='\\' && !nextliteral)
				{
					//Only print out next character no matter what. Do not interpret.
					nextliteral = true;
				}
				else
				{
					nextliteral = false;
					if ( ((c>=' ') && (c<='~')) || ((c>=128) && (c<255)) )
					{
						fputc(c, file);
					}
				}
			}
		}
		//Store the recent characters for when we have to go back for a number:
		for (j=0; j<oldchar-1; j++) oc[j]=oc[j+1];
		oc[oldchar-1]=c;
		if (!intextobject)
		{
			if (seen2("BT", oc))
			{
				//Start of a text object:
				intextobject = true;
			}
		}
	}
}
コード例 #8
0
ファイル: Input.c プロジェクト: Acidburn0zzz/code-samples
/**
 * @brief Parses the application's command-line arguments
 *
 * @param[in] argc          The number of input arguments
 * @param[in] argv        	The input arguments
 * @param[in] rank          The MPI rank of the calling process
 * @param[in] size          The total number of MPI processes available
 * @param[out] domSize  	The parsed domain size (2D)
 * @param[out] topSize		The parsed topology size (2D)
 * @param[out] useFastSwap	The parsed flag for fast block swap
 * @return		     		The parsing status (STATUS_OK indicates a successful parse)
 */
int ParseCommandLineArguments(int argc, char ** argv, int rank, int size, int2 * domSize, int2 * topSize, int * useFastSwap)
{
	int canPrint = (rank == MPI_MASTER_RANK);
	int argIdx;

	// If help is requested, all other arguments will be ignored
	if ((FindAndClearArgument("-h", argc, argv) != -1) || (FindAndClearArgument("--help", argc, argv) != -1))
	{
		if (canPrint)
		{
			PrintUsage(argv[0]);
		}

		// This simply prevents the application from continuing 
		return STATUS_ERR;
	}

	// Check if fast swapping was requested
	* useFastSwap = (FindAndClearArgument("-fs", argc, argv) != -1);

	// Topology information must always be present
	argIdx = FindAndClearArgument("-t", argc, argv);
	if (argIdx == -1)
	{
		OneErrPrintf(canPrint, "Error: Could not find the topology information.\n");
		return STATUS_ERR;
	}
	else
	{
		topSize->x = ExtractNumber(argIdx + 1, argc, argv);
		topSize->y = ExtractNumber(argIdx + 2, argc, argv);

		// At least the first topology dimension must be specified
		if (topSize->x <= 0)
		{
			OneErrPrintf(canPrint, "Error: The topology size is invalid (first value: %d)\n", topSize->x);
			return STATUS_ERR;
		}

		// If the second topology dimension is missing, it will default to 1
		if (topSize->y <= 0)
		{
			topSize->y = 1;
		}
	}

	// The domain size information is optional
	argIdx = FindAndClearArgument("-d", argc, argv);
	if (argIdx == -1)
	{
		domSize->x = domSize->y = DEFAULT_DOMAIN_SIZE;
	}
	else
	{
		domSize->x = ExtractNumber(argIdx + 1, argc, argv);
		domSize->y = ExtractNumber(argIdx + 2, argc, argv);

		// At least the first domain dimension must be specified
		if (domSize->x < MIN_DOM_SIZE)
		{
			OneErrPrintf(canPrint, "Error: The local domain size must be at least %d (currently: %d)\n", MIN_DOM_SIZE, domSize->x);
			return STATUS_ERR;
		}
		
		// If the second domain dimension is missing, it will default to the first dimension's value
		if (domSize->y <= 0)
		{
			domSize->y = domSize->x;
		}
	}

	// At the end, there should be no other arguments that haven't been parsed
	for (int i = 1; i < argc; ++i)
	{
		if (strlen(argv[i]) > 0)
		{
			OneErrPrintf(canPrint, "Error: Unknown argument (\"%s\")\n", argv[i]);
			return STATUS_ERR;
		}
	}

	// If we reach this point, all arguments were parsed successfully
	if (canPrint)
	{
		printf("Topology size: %d x %d\n", topSize->x, topSize->y);
		printf("Local domain size (current node): %d x %d\n", domSize->x, domSize->y);
		printf("Global domain size (all nodes): %d x %d\n", topSize->x * domSize->x, topSize->y * domSize->y);
	}

	return STATUS_OK;
}
コード例 #9
0
ファイル: models.c プロジェクト: ChunHungLiu/GtkRadiant
/*
=================
Cmd_Base
=================
*/
void Cmd_Base (void)
{
	vec3_t		base_xyz[MAX_VERTS];
	triangle_t	*ptri;
	int			i, j, k;
#if 1
#else
	int		time1;
#endif
	char	file1[1024];
	char	file2[1024];

	GetScriptToken (false);

	if (g_skipmodel || g_release || g_archive)
		return;

	printf ("---------------------\n");
#if 1
	sprintf (file1, "%s/%s", cdpartial, token);
	printf ("%s  ", file1);

	ExpandPathAndArchive (file1);

	sprintf (file1, "%s/%s", cddir, token);
#else
	sprintf (file1, "%s/%s.%s", cdarchive, token, trifileext);
	printf ("%s\n", file1);

	ExpandPathAndArchive (file1);

	sprintf (file1, "%s/%s.%s", cddir, token, trifileext);

	time1 = FileTime (file1);
	if (time1 == -1)
		Error ("%s doesn't exist", file1);
#endif
//
// load the base triangles
//
	if (do3ds)
		Load3DSTriangleList (file1, &ptri, &model.num_tris, NULL, NULL);
	else
		LoadTriangleList (file1, &ptri, &model.num_tris, NULL, NULL);


	GetScriptToken (false);
	sprintf (file2, "%s/%s.pcx", cddir, token);
//	sprintf (trans_file, "%s/!%s_a.pcx", cddir, token);

	printf ("skin: %s\n", file2);
 	Load256Image (file2, &BasePixels, &BasePalette, &BaseWidth, &BaseHeight);

	if (BaseWidth != SKINPAGE_WIDTH || BaseHeight != SKINPAGE_HEIGHT)
	{
		if (g_allow_newskin)
		{
			ScaleWidth = BaseWidth;
			ScaleHeight = BaseHeight;
		}
		else
		{
			Error("Invalid skin page size: (%d,%d) should be (%d,%d)",
				BaseWidth,BaseHeight,SKINPAGE_WIDTH,SKINPAGE_HEIGHT);
		}
	}
	else
	{
		ScaleWidth = (float)ExtractNumber(BasePixels, ENCODED_WIDTH_X,
			ENCODED_WIDTH_Y);
		ScaleHeight = (float)ExtractNumber(BasePixels, ENCODED_HEIGHT_X,
			ENCODED_HEIGHT_Y);
	}

//
// get the ST values
//
	BuildST (ptri, model.num_tris,false);

//
// run through all the base triangles, storing each unique vertex in the
// base vertex list and setting the indirect triangles to point to the base
// vertices
//
	for (i=0 ; i<model.num_tris ; i++)
	{
		for (j=0 ; j<3 ; j++)
		{
			// get the xyz index
			for (k=0 ; k<model.num_xyz ; k++)
				if (VectorCompare (ptri[i].verts[j], base_xyz[k]))
					break;	// this vertex is already in the base vertex list

			if (k == model.num_xyz)
			{ // new index
				VectorCopy (ptri[i].verts[j], base_xyz[model.num_xyz]);

				if(clustered)
					ReplaceClusterIndex(k, ptri[i].indicies[j], (int **)&clusters, (IntListNode_t **)&vertLists, (int *)&num_verts, (int *)&new_num_verts);

				model.num_xyz++;
			}

			triangles[i].index_xyz[j] = k;

			// get the st index
			for (k=0 ; k<model.num_st ; k++)
				if (triangle_st[i][j][0] == base_st[k].s
				&& triangle_st[i][j][1] == base_st[k].t)
					break;	// this vertex is already in the base vertex list

			if (k == model.num_st)
			{ // new index
				base_st[model.num_st].s = triangle_st[i][j][0];
				base_st[model.num_st].t = triangle_st[i][j][1];
				model.num_st++;
			}

			triangles[i].index_st[j] = k;
		}
	}

	// build triangle strips / fans
	BuildGlCmds ();
}