Example #1
0
// Recursive function that returns a list containing all of the permutations of the set
NodePtr Permutations::permutate(int set[], int size)
{
    NodePtr large = NULL;
    if(size==1)
    {
        large = new Node;
        int* arr = new int[1];
        arr[0] = set[0];
        large->setPtr = arr;
        large->setSize = 1;
        large->next = NULL;
        return large;
    }
    else
    {
        int* tmp = new int[size];
        for (int i = 0; i < size; i++)
        {
            tmp[i] = set[i];
        }
        NodePtr small = permutate(tmp, size-1);
        insert(size, small, large);
        delete[]tmp;
        return large;
    }
}
Example #2
0
/*
	_search_fill fills the buffer with random data according to
	a pdf has the entropy specified in the source. It calculates
    the cdf then populate the buffer by searching in the cdf for 
    the random number. Sometimes this approach is called roulette
    algorithm. The binary search is expected to add 8x factor.
*/
int entropy_search_fill(struct source *ds, void *buf, unsigned int size){
	
	int i = 0;
	double pdf[PDF_SIZE];
	double cdf[PDF_SIZE];
	unsigned char symbols_table[PDF_SIZE];

	//Calculate pdf according to the given entropy
	generate_pdf(pdf, PDF_SIZE, ds-> s_entropy);
#ifndef _FB_FILEBENCH_H
	print_pdf(pdf, 5);
	printf("PDF entropy is: %f\n" ,pdf_entropy(pdf, PDF_SIZE));
#endif
	//Calculate cdf from the pdf
	calculate_cdf(pdf, PDF_SIZE, cdf);

	//initializing the symbol table
	for(i=0; i< PDF_SIZE; i++)
		symbols_table[i] = (unsigned char)i;

	//shuffle the symbols table
	permutate(symbols_table, PDF_SIZE);

	for(i=0; i < size; i++){
		((unsigned char*)buf)[i] = symbols_table[binary_search(rand()/(double)RAND_MAX, cdf, PDF_SIZE)];
	}
	return 0;
}
int main (void)
{
    std::vector<char> A = {'a', 'b', 'c', 'd', 'e', 'f'};
    std::vector<int> P = {4, 5, 3,  2, 1, 0};
    std::cout << A << std::endl;
    std::cout << P << std::endl;
    permutate(A, P);
    std::cout << A << std::endl;
    return 0;
}
 void permutate(const map<char, vector<string> > &dict, const string digits, const string curPerm, vector<string> &re){
     if (digits == ""){
         re.push_back(curPerm);
         return;
     }
     vector<string> letters = dict.find(digits[0])->second;
     for (size_t i = 0; i < letters.size(); i++){
         permutate(dict, digits.substr(1), curPerm + letters[i], re);
     }
 }
Example #5
0
void permutate(char *a, int level, int length) {
  if (level == length) {
    printf("%s\n", a);
  } else {
    for (int branch = level; branch <= length; branch++) {
      swap(&a[level], &a[branch]);
      permutate(a, level + 1, length);
      swap(&a[level], &a[branch]);
    }
  }
}
Example #6
0
void do_string(const char *str)
{
	least_overlap = strlen(str);
	strcpy(orig, str);

	seq_no = 0;
	out[least_overlap] = '\0';
	least_overlap ++;

	permutate(count_letters(str), least_overlap - 2, 0);
	printf("%s -> %s, overlap %d\n", str, best, least_overlap);
}
Example #7
0
void permutate(char *str, int s, int e){
  if(s>=e)
    printf("%s\n", str);
  else{
    int i;
    for(i=s; i<=e; i++){
      moveClockwise(str, s, i);
      permutate(str, s+1, e);
      moveAntiClockwise(str, s, i);
    }
  }
}
Example #8
0
int main()
{
int i;
char str1[100],str[100];
scanf("%s",str1);
for(k=0;k<strlen(str1);k++)
{
count=0;
j=0;
str[count]=str1[k];
permutate(str,str1,count,j,k);
}
}
Example #9
0
int main (int argc, char* argv[]) {
  printf("String to permutate> ");
  fgets(buffer, 256, stdin);

  char *str = buffer;
  str[strlen(str) - 1] = '\0';

  permutate(str, 0, strlen(str) - 1);

  getchar();

  return 0;
}
Example #10
0
void permutate(char str[], int start, int end)
{
    if (start == end) {
        puts(str);
        return;
    }
    for (int i=start; i<end; i++) {
        swap(str,start,i);
        permutate(str, start+1, end);
        swap(str, start,i);
    }
    
}
Example #11
0
void permutate(char *s, int start, int end) {
    if (start < end) {
        for (int i = start; i <= end; ++i) {
            rotate_left(s, start, i);
            permutate(s, start + 1, end);
            rotate_right(s, start, i);
        }
    } else {
        if (comma) printf(",");
        printf("%s", s);
        comma = 1;
    }
}
Example #12
0
void permutate(int *arr,int r,int i,int total,int n,int visited[],int power,int start)
{
    int j;

//int **store=(int**)malloc(sizeof(int**)*power);
int store[power][2];


if(i==n)
{

    int val;
    char str2[9],str1[9];
    int a[100000];
    itoa(arr[n-1], str1,10);
    itoa(arr[n], str2, 10);
    strcat(str1,str2);
    ++x;
    val=atoi(str1);
      a[x]=val;
//printf("%d-",a[x]);
  //printf("%d %d \n",*(arr+(n-2)), *(arr+(n-1)));
  if(visited[a[x]]==0)
{
		//printf("%d %d %d %d ",arr[0] ,arr[1],arr[2],arr[3]);
		 add( *(arr+(n-1)),*(arr+(n)),store,x,total,power,start,n+1);
	printf("\n");
	visited[a[x]]=1;
}


 //printf("%d",x);
  //store[x][0]=*(arr+(n-2));
  //store[x][1]=*(arr+(n-1));
  //printf("value of store :");
  //printf("%d %d  %d \n", store[x][0],store[x][1] ,x);

}
else
for(j=i;j<=n;j++)
{
	swap(arr+i,arr+j);
	permutate(arr,r,i+1 ,total,n,visited,power,start);
	swap(arr+i,arr+j);
}

//printf("%d",x);
//compare((int**)store,);
return;
}
Example #13
0
int main(int argc, char *argv[]) {
    char l[1024];
    FILE *f = fopen(argv[1], "r");
    while (fgets(l, 1024, f)) {
        replace(l, '\n', '\0');

        comma = 0;
        int len = strlen(l);
        qsort(l, len, sizeof(char), compare);
        permutate(l, 0, len - 1);
        printf("\n");
    }
    fclose(f);
    return 0;
}
Example #14
0
// Generates permutations for set of size n
void Permutations::generate(int n) {
    if (myPerms != NULL) { // First clean the permutations if necessary
        removeAll();
    }

    int* aSet = new int[n];
    // Populate the set with the first n whole numbers
    for (int i = 0; i < n; i++) {
        aSet[i] = i+1;
    }

    // Use the recursive permutations function to generate all the permutations
    myPerms = permutate(aSet, n);
    // Deallocate aSet
    delete [] aSet;
}
 /**
 * 先构造词典,然后DFS
 */
 vector<string> letterCombinations(string digits) {
     //init dict
     map<char, vector<string> > dict;
     dict['0'] = dict['1'] = vector<string>();
     char c = 'a';
     for(int i = 2; i <= 9; i++) {
         vector<string> letters;
         for (int j = 0; j < 3; j++)
             letters.push_back(string(1, c++));
         if (i == 7 || i == 9){
             letters.push_back(string(1, c++));
         }
         dict['0' + i] = letters;
     }
     //DFS
     vector<string> re;
     permutate(dict, digits, "", re);
     return re;
 }
Example #16
0
void permutate(int n_letters, int pos, int overlap)
{
	int i, ol;
	if (pos < 0) {
                /* if enabled will show all shuffles no worse than current best */
	//	printf("%s: %d\n", out, overlap);

                /* if better than current best, replace it and reset counter */
		if (overlap < least_overlap) {
			least_overlap = overlap;
			seq_no = 0;
		}

                /* the Nth best tie has 1/N chance of being kept, so all ties
                 * have equal chance of being selected even though we don't
                 * how many there are before hand
                 */
		if ( (double)rand() / (RAND_MAX + 1.0) * ++seq_no <= 1)
			strcpy(best, out);

		return;
	}

        /* standard "try take the letter; try take not" recursive method */
	for (i = 0; i < n_letters; i++) {
		if (!letters[i]->count) continue;

		out[pos] = letters[i]->c;
		letters[i]->count --;
		ol = (letters[i]->c == orig[pos]) ? overlap + 1 : overlap;

                /* but don't try options that's already worse than current best */
		if (ol <= least_overlap)
			permutate(n_letters, pos - 1, ol);

		letters[i]->count ++;
	}
	return;
}
Example #17
0
void permutate(char str[],char str1[],int count,int j,int k)
{
int i;
for(i=j;i<strlen(str1);i++)
{
if(i==k)
 continue;

if(i<strlen(str1)-2)
{
	count++;
	str[count]=str1[i];
  permutate(str,str1,count,j);
}
else
{
str[count]=str1[i];
count++;
str[count]=str1[i+1];
}

}
}
Example #18
0
int main()
{
	int power, p,n1,n2,i;
	int visited[10000];
	for(i=0;i<10000;i++)
        {
            visited[i]=0;
        }
	int k=0;
	printf("enter the number of players: ");
	scanf("%d",&p);
	printf("enter the starting number: ");
	scanf("%d",&n1);
	printf("enter the ending number: ");
	scanf("%d",&n2);
	int *arr=(int*)malloc(((n2-n1)-1)*sizeof(int*));

	for( i=n1+1;i<n2;i++)
	{
		arr[k]=i;
		k++;
	}
	for( i=0;i<(n2-n1-1);i++)
	printf("%d \n",arr[i]);

	int fact=factorial((n2-n1-1));
	int total=fact/2;
    power=pow((n2-n1-1),2);

	printf("Total number of nodes in graph : %d",power);
	printf("\n");
	permutate(arr,p,0,total, (n2-n1-2),visited,power,n1);//permutation calls with one less node than than the total number of nodes

	return 0;

	}
Example #19
0
/*-----------------------------------------------------------
UN-DES Main procedure
Description:
-----------------------------------------------------------*/
void undes(char m[8],char key[8])
{
    char  ip[8];
    char  lin[4];
    char  rin[4];
    char  lup[4];
    char  rup[4];
    char  tmp[6];
    char  tmp4[4];
    char  subkey[16][6];
    char  i,j;
    union hbyte ip1;
    union hbyte ipr;
    ip1.abyte=0;
    ipr.abyte=0;

    /* Subkey Generate */
    Gsubkey(key,subkey);

    /* IP trans */
    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit6;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit6;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit6;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit6;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit6;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit6;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit6;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit6;
    ip[7]=ipr.abyte;                   /* byte7: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit4;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit4;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit4;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit4;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit4;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit4;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit4;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit4;
    ip[6]=ipr.abyte;                   /* byte6: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit2;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit2;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit2;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit2;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit2;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit2;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit2;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit2;
    ip[5]=ipr.abyte;                   /* byte5: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit0;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit0;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit0;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit0;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit0;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit0;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit0;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit0;
    ip[4]=ipr.abyte;                   /* byte4: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit7;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit7;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit7;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit7;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit7;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit7;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit7;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit7;
    ip[3]=ipr.abyte;                   /* byte3: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit5;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit5;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit5;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit5;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit5;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit5;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit5;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit5;
    ip[2]=ipr.abyte;                   /* byte2: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit3;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit3;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit3;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit3;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit3;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit3;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit3;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit3;
    ip[1]=ipr.abyte;                   /* byte1: 8 bits */

    ip1.abyte=m[0];  ipr.ibyte.bit7=ip1.ibyte.bit1;
    ip1.abyte=m[1];  ipr.ibyte.bit6=ip1.ibyte.bit1;
    ip1.abyte=m[2];  ipr.ibyte.bit5=ip1.ibyte.bit1;
    ip1.abyte=m[3];  ipr.ibyte.bit4=ip1.ibyte.bit1;
    ip1.abyte=m[4];  ipr.ibyte.bit3=ip1.ibyte.bit1;
    ip1.abyte=m[5];  ipr.ibyte.bit2=ip1.ibyte.bit1;
    ip1.abyte=m[6];  ipr.ibyte.bit1=ip1.ibyte.bit1;
    ip1.abyte=m[7];  ipr.ibyte.bit0=ip1.ibyte.bit1;
    ip[0]=ipr.abyte;                   /* byte0: 8 bits */

    /* Generate L0, R0 */
    lin[3]=ip[7];lin[2]=ip[6];lin[1]=ip[5];lin[0]=ip[4];  /* L0 */
    rin[3]=ip[3];rin[2]=ip[2];rin[1]=ip[1];rin[0]=ip[0];  /* R0 */

    /* Generate Ri, Li (16 Times) */
    for(j=0;j<16;j=j+1){

        for(i=0;i<4;i=i+1){  lup[i]=lin[i];  }
        for(i=0;i<4;i=i+1){  rup[i]=rin[i];  }
        /* Expand Operation */
        expand(rup,tmp);
        /* 48 bits MOD 2 */
        for(i=0;i<6;i=i+1){  tmp[i]=tmp[i]^subkey[15-j][i];  }
        /* Compress Operation */
        compress(tmp,rin);
        /* Permutation */
        permutate(rin,tmp4);
        /* 32 bits MOD 2 */
        for(i=0;i<4;i=i+1){  rin[i]=lup[i]^tmp4[i];  }        /* Ri */
        for(i=0;i<4;i=i+1){  lin[i]=rup[i];  }                /* Li */

    }
    /* Generate R16, L16 */
    for(i=0;i<4;i=i+1){  tmp4[i]= rin[i];  }
    for(i=0;i<4;i=i+1){  rin[i] = lin[i];  }
    for(i=0;i<4;i=i+1){  lin[i] =tmp4[i];  }

    /* IP(-1) trans */
    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit0;   /* 40 */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit0;   /* 8 */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit0;   /* 48 */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit0;   /* 16 */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit0;   /* 56 */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit0;   /* 24 */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit0;   /* 64 */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit0;   /* 32 */
    ip[7]=ipr.abyte;                   /* byte7: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit1;   /* 39 */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit1;   /* 7 */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit1;   /* 47 */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit1;   /* 15 */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit1;   /* 55 */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit1;   /* 23 */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit1;   /* 63 */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit1;   /* 31 */
    ip[6]=ipr.abyte;                   /* byte6: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit2;   /* 38 */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit2;   /* 6 */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit2;   /* 46 */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit2;   /* 14 */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit2;   /* 54 */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit2;   /* 22 */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit2;   /* 62 */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit2;   /* 30 */
    ip[5]=ipr.abyte;                   /* byte5: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit3;   /* 37 */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit3;   /*  */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit3;   /*  */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit3;   /*  */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit3;   /*  */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit3;   /*  */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit3;   /*  */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit3;   /* 29 */
    ip[4]=ipr.abyte;                   /* byte4: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit4;   /* 36 */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit4;   /*  */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit4;   /*  */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit4;   /*  */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit4;   /*  */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit4;   /*  */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit4;   /*  */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit4;   /* 28 */
    ip[3]=ipr.abyte;                   /* byte3: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit5;   /*  */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit5;   /*  */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit5;   /*  */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit5;   /*  */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit5;   /*  */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit5;   /*  */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit5;   /*  */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit5;   /*  */
    ip[2]=ipr.abyte;                   /* byte2: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit6;   /*  */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit6;   /*  */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit6;   /*  */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit6;   /*  */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit6;   /*  */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit6;   /*  */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit6;   /*  */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit6;   /*  */
    ip[1]=ipr.abyte;                   /* byte1: 8 bits */

    ip1.abyte=rin[3];  ipr.ibyte.bit7=ip1.ibyte.bit7;   /*  */
    ip1.abyte=lin[3];  ipr.ibyte.bit6=ip1.ibyte.bit7;   /*  */
    ip1.abyte=rin[2];  ipr.ibyte.bit5=ip1.ibyte.bit7;   /*  */
    ip1.abyte=lin[2];  ipr.ibyte.bit4=ip1.ibyte.bit7;   /*  */
    ip1.abyte=rin[1];  ipr.ibyte.bit3=ip1.ibyte.bit7;   /*  */
    ip1.abyte=lin[1];  ipr.ibyte.bit2=ip1.ibyte.bit7;   /*  */
    ip1.abyte=rin[0];  ipr.ibyte.bit1=ip1.ibyte.bit7;   /*  */
    ip1.abyte=lin[0];  ipr.ibyte.bit0=ip1.ibyte.bit7;   /*  */
    ip[0]=ipr.abyte;                   /* byte0: 8 bits */

    m[7]=ip[7];
    m[6]=ip[6];
    m[5]=ip[5];
    m[4]=ip[4];
    m[3]=ip[3];
    m[2]=ip[2];
    m[1]=ip[1];
    m[0]=ip[0];
    return;
}
Example #20
0
void permutation(char *str){
  int len=strlen(str);
  permutate(str, 0, len-1);
}
Example #21
0
int main()
{
    char arr[3] = "abc";
    permutate(arr, 0, (int)strlen(arr));
    return 0;
}
Example #22
0
File: ld.cpp Project: nealey/vera
/*------------------------------------------------------------------------*/
static int prc1(const char *file, const char *user) /* Process indirect file */
{
  FILE *fpo;
  FILE *fp = fopen(file, "r");
  if ( fp == 0 )
  {
    fprintf(stderr, "ld: can't open indirect file\n");
    return 1;
  }
  fpo = fopen(tmpnam(rspname), "w");
  if ( fpo == 0 )
  {
    fprintf(stderr, "ld: can't create temp file\n");
    return 1;
  }
  while ( fgets(fl, sizeof(fl), fp) )
  {
    if ( strncmp(fl, "noperm", 6) == 0 )
    {
      fputs(fl+6, fpo);
      continue;
    }
    if ( strncmp(fl, "file", 4) == 0 || strncmp(fl, "lib", 3) == 0 )
    {
      char *ptr = fl;
      // skip word and spaces
      while ( *ptr != ' ' && *ptr != '\t' && *ptr != 0 )
        ptr++;
      while ( isspace(*ptr) )
        ptr++;
      if ( user != NULL )
        permutate(ptr, user);
      if ( isbor )
      {
        fputs(ptr, fpo);
        continue;
      }
      *(ptr-1) = '\0';
      while ( true )
      {
        while ( isspace(*ptr) )
          ptr++;
        if ( *ptr == '\0' )
          break;
        fputs(fl, fpo);
        putc(' ', fpo);
        while ( *ptr != ' ' && *ptr != '\t' && *ptr != 0 )
        {
          putc(*ptr, fpo);
          ptr++;
        }
        putc('\n', fpo);
      }
      continue;
    }
    if ( !isbor )
      fputs(fl, fpo);
  }
  fclose(fp);
  fclose(fpo);
  return 0;
}
Example #23
0
int PerlinGenerator::index(int ix, int iy, int iz)
{
    return permutate(ix + permutate(iy + permutate(iz)));
}
Example #24
0
int entropy_permutate_fill(struct source *ds, void *buf, unsigned int size){
    int err = entropy_cont_fill(ds, buf, size);
    permutate((unsigned char*)buf,size); 
	return err;
}