Ejemplo n.º 1
0
void EncodeMessage(struct ppm *ppmFile,char* text)
{
	BitArray(primes,MAX_LIMIT);
	Eratosthenes(primes);
	char encode[2],znak[2];
	bool end=false;
	encode[0] = CHAR_BIT;
	znak[0] = CHAR_BIT;
	short int j=0;
	unsigned n=0;
	znak[1] = text[n];
	for (unsigned long i=2;i<MAX_LIMIT;i++)
	{
		if(i>3*ppmFile->xsize*ppmFile->ysize) break;
		if (GetBit(primes,i)==0)
		{
			/* Pomocna premenna kde sa nastavi prislusny bit */
			encode[1]=ppmFile->data[i];
			//SetBit(encode,0,GetBit(znak,j));
			/* SetBit ani GetBit nepouzity lebo ocakava long unsigned int* */
			DU1__SET_BIT(znak,j,DU1__GET_BIT(znak,j));
			/* Po zakodovani sa ulozi spat do struktury */
			ppmFile->data[i]=encode[1];
			j++;
			if (j==CHAR_BIT)
			{
				/* Nulovy znak zapisany, cyklus sa moze ukocnit */
				if (end) break;
				j=0;
				znak[1]=text[++n];
				if (znak[1]==0) end=true;
			}
		}
	}
}
Ejemplo n.º 2
0
int main(void)
{
    BitArray(p,N);
    int counter = 0,j,i;
    unsigned long long pole[NUMBER_COUNT];

    Eratosthenes(p);   // nastavenie bitov podla prvocisel

    i = N;

    // ulozenie do pola, kvoli vypisaniu vzostupne

    while (counter < NUMBER_COUNT)
    {
        if (GetBit(p,i) == (unsigned long)0)
        {
            pole[counter]=i;
            counter++;
        }
        i--;
    }

    j = NUMBER_COUNT - 1;

    while (j >= 0)
    {
        printf("%llu\n",pole[j]);  // vypis prvocisel
        j--;
    }

    return 0;
}
Ejemplo n.º 3
0
int main(int argc, const char* argv[])
{
	if (argc != 2) {
		FatalError("Neplatne argumenty programu!");
	}

	struct ppm* image = ppm_read(argv[1]);
	if (!image) {
		return EXIT_FAILURE;
	}

	BA_create(bit_array, N); 
	Eratosthenes(bit_array);

	int ch, nbits; 
	ch = nbits = 0; 

	unsigned long image_size = image->xsize * image->ysize * 3;
	for (unsigned long i = 2; i < image_size; i++) {
		
		if (BA_get_bit(bit_array, i) == 0) {

			/** :) kdyz najdeme prvocislo tak to znamena ze 
			 * v poli image->data mame v LSB bitu v bajtu 
			 * na indexu i ulozeny jeden bit znaku zakodovane
			 * zpravy
			 */ 

			// n-ty bit (nbits) znaku (ch) nastavime na hodnotu LSB bitu
			// prvociselne polozky pole image->data
         		DU1_SET_BIT((&ch), nbits, DU1_GET_BIT((&image->data[i]), 0));

			if((++nbits) == CHAR_BIT) { // mame j*z cely znak? 

				if (ch == 0) {  
					break; 
				} else if (isprint(ch)) {
					printf("%c", ch);
					nbits = 0; 
				} else {  
					FatalError("Zprava obsahuje netisknutelny znak!");
				}
			}
		}	
	}

	free(image);

	return EXIT_SUCCESS; 	
}
Ejemplo n.º 4
0
int main ( int argc, char* argv[] ) {
   srand ( ( unsigned int ) time ( NULL ) ); //设置随机种子
   if ( 2 > argc ) { printf ( "Usage: %s <maxInt>\n", argv[0] ); return -1; }
   int n = atoi ( argv[1] ); //简化起见,不考虑非正的情况
   Eratosthenes ( n, PRIMEFILE );
   for ( int i = 0; i < 13; i++ ) { //做13次随机测试(限于MAX_RAND,覆盖范围不超过0x7FFF)
      int low = dice ( n );
      printf ( "The smallest prime number no less than %8d (%05X) is %8d\n", low, low, primeNLT ( low, n, PRIMEFILE ) );
   }
   for ( int i = 0; i < 13; i++ ) { //做13次等间距测试
      printf ( "The smallest prime number no less than %8d (%05X) is %8d\n", n * i / 13, n * i / 13, primeNLT ( n * i / 13, n, PRIMEFILE ) );
   }
   return 0;
}
Ejemplo n.º 5
0
/* ==================================================================== */
int main(void)
{
    BitArray(primes, N);
    Eratosthenes(primes);

    unsigned long last_primes[LAST_N] = { 0 };
    for (size_t i = N, ii = LAST_N; --i, ii; ) {
        if (!GetBit(primes, i))
            last_primes[--ii] = i;
    }

    for (size_t i = 0; i < LAST_N; ++i) {
        fprintf(stdout, "%lu\n", last_primes[i]);
    }

    return 0;
}
Ejemplo n.º 6
0
int main()
{
  int t,i,j;
  int m,n;
  scanf("%d",&t);
  for(i=0; i<t; i++){
    scanf("%d",&m);
    scanf("%d",&n);
    Eratosthenes(n,a,b);
    for(j=m; j<=n; j++){
      if(j>10000000){
	if(b[j-10000001] == 1){
	  printf("%d\n",j+1);
	}
      }
      else{
	if(a[j] == 1){
	  printf("%d\n",j+1);
	}
      }
    }
  }
  return 0;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	if (argc == 2)				// ak nie je zadany chybny pocet argumentov
	{
		struct ppm *picture = ppm_read(argv[1]);  // nacitanie struktury
		char sprava = 0,index2=0,bit;
		unsigned long index;
		int nullbyte = 0;
		
		if (picture == NULL) 			// ak nacitanie skoncilo s chybou
			FatalError("Chybne zadany subor\n");
		
		BitArray(bitmap,LIMIT);   // iniciaizacia bit. pola
	
		Eratosthenes(bitmap);   // vypocet prvociselnych indexov
			
		for (index=2;index <= (LIMIT); index++)	
		{
			if (GetBit(bitmap,index) == 0)   // prvociselny index
			{	
				bit = DU1_GET_BIT((&(picture->data)[index+1]),0); // vyber LSB z bytu
				DU1_SET_BIT((&sprava),index2,bit);				  // nastav na nasledujuci index vybrany bit
												
				if (index2 < (BYTE - 1))							  // ci uz nie je zaplneny cely byte
				{
					index2++;
				} 
					else if ((sprava != '\0') && (isprint(sprava)))   // ak nie je znak nulovy alebo netlacitelny
					{
						printf("%c",sprava);						  // vytlaci 1 znak zo spravy
						index2 = 0; 								  // vynulue pocet nast. bitov a znak
						sprava = 0;
					}
						else if (sprava == '\0')					 // ak je znak nulovy -> koniec spravy
						{
							printf("\n");
							nullbyte = 1;
							break;
						}
						else                						// ak je znak netlacitelny -> fatal error
							{									
								free(picture);
								FatalError("Sprava ulozena v subore: %s nie je korektna\n",argv[1]);
							}
			}		
		}
		
	if (nullbyte == 0)
	{
		free(picture);
		FatalError("Sprava ulozena v subore: %s nie je korektne ukoncena\n",argv[1]);
		return 1;
	} else
		{
			free(picture);													// uvolnenie alokovanej pamate
			return 0;
		}
		
	} else
		{
			FatalError("Nespravne zadane argumenty\n");
			return 1;
		}
	
	
}