Пример #1
0
    void des(const std::string& inp, std::string& key, std::string& p_encrypted) {
        boost::uint32_t c = bpermute(key.data(), 28, PC1[0]);
        boost::uint32_t d = bpermute(key.data(), 28, PC1[1]);
        boost::uint32_t l = rrotate(bpermute(inp.data(), 32, IP[0]),31);
        boost::uint32_t r = rrotate(bpermute(inp.data(), 32, IP[1]),31);

        boost::uint32_t rot=1;
        for(boost::uint32_t i=0;i<16;++i){
            boost::uint32_t k[2]=
            {
                permute(rrotate28(c,rot),24,PC2[1]),
                permute(rrotate28(d,rot),24,PC2[0])
            };

            for(boost::uint32_t j=0; j<8; ++j){
                boost::uint32_t x=k[j>>2]>>(j&3)*6;
                boost::uint32_t b=(rrotate(r,j*4)^x)&0x3f;
                boost::uint32_t s=(S[j][b>>3]>>((b&7)*4))&0xf;
                l^=rrotate(permute(s<<j*4,32,P),31);
            }
            boost::uint32_t t=l;
            l=r;
            r=t;
            ++rot;
            if(i!=0 && i!=7 && i!=14)
                ++rot;
        }
        char v[8]={};
        packbe(v,0,rrotate(r,1));
        packbe(v,4,rrotate(l,1));
        l=bpermute(v,32,FP[0]);
        r=bpermute(v,32,FP[1]);
        char out[8]={};
        packbe(out,0,l);
        packbe(out,4,r);
        p_encrypted.assign(out, 8);
    }
Пример #2
0
/* Function to print permutations of string
This function takes three parameters:
1. String
2. Starting index of the string
3. Ending index of the string. */
void permute(char *a, int i, int n)
{
	int j;
	if (i == n && a[0]!=0)
		printf("%s\n", a);
	else
	{
		for (j = i; j <= n; j++)
		{
			swap((a + i), (a + j));
			permute(a, i + 1, n);
			swap((a + i), (a + j)); //backtrack
		}
	}
}
Пример #3
0
void main() {
	size_t * perm = malloc(sizeof(size_t) * 1000);
	struct rtree_t t = {0};
	int i, j, k;
	float pos[1000][3];
	float sml[1000];
	intptr_t key[1000];
	int l = 0;
	for(i = 0; i < 10; i++) {
		for(j = 0; j < 10; j++) {
			for(k = 0; k < 10; k++) {
				pos[l][0] = i * 0.1 * (1<<20);
				pos[l][1] = j * 0.1 * (1<<20);
				pos[l][2] = k * 0.1 * (1<<20);
				sml[l] = 0;
				key[l] = peano_hilbert_key(pos[l][0], pos[l][1], pos[l][2], 20);
				l++;
			}
		}
	}

	gsl_heapsort_index(perm, key, 1000, sizeof(intptr_t), (void*)intptr_t_compare);

	float (*__pos)[3] = permute(perm, pos, 3 * sizeof(float), 3 * sizeof(float), 1000, 1000);
	float * __sml = permute(perm, sml, sizeof(float), sizeof(float), 1000, 1000);
	intptr_t * __key = permute(perm, key, sizeof(intptr_t), sizeof(intptr_t), 1000, 1000);
	rtree_build(&t, __pos, __sml, __key, 1000);
	float dist[10];
	intptr_t nei[10];
	int nused = 0;
	float hhint = 100000;
	float p[3] = {499999, 499999,499999};

	rtree_neighbours(&t, p, __pos, 1000, nei, dist, 10, &nused, NULL);
	printf("hello\n");
}
Пример #4
0
void permute(char *a, int i, int n) {
	int j;
	if (i == n) {
		strcpy(perm_head -> w, a);
		perm_head -> next = malloc(sizeof(permutes));
		perm_head = perm_head -> next;
	}
	else {
		for (j = i; j <= n; j++) {
			swap(a+i, a+j);
			permute(a, i+1, n);
			swap(a+i, a+j);
		}
	}
}
void permute(char *a, int i, int n) 
{
   int j; 
   if (i == n)
     printf("%s\n", a);
   else
   {
        for (j = i; j <= n; j++)
       {
          swap((a+i), (a+j));
          permute(a, i+1, n);
          swap((a+i), (a+j)); 
       }
   }
} 
Пример #6
0
void permute (char * str, int start, int end)
{
	if (start == end)
		printf ("%s\n", str);
	else
	{
		int j;
		for (j = start; j <= end; j++)
		{
			swap ((str + start), (str + j));
			permute (str, start + 1, end);
			swap ((str + start), (str + j));
		}
	}
}
Пример #7
0
void permute(char *a, int i, int n) 
{
   int j; 
   if (i == n-1)
     printf("%s\n", a);
   else
   {
        for (j = i; j <n; j++)
       {
          swap(&a[i], &a[j]);
          permute(a, i+1, n);
          swap(&a[i], &a[j]);//backtrack
       }
   }
} 
Пример #8
0
//function to generate permuted array and make the corresponding trees simultaneously with help from above function
void permute(int *a, int i, int n)
{
    int j;
    if(i==n) {
        maketree(a,n);
    }
    else {
        for (j = i; j <= n; j++)
        {
            swap((a+i), (a+j));
            permute(a, i+1, n);
            swap((a+i), (a+j)); //backtrack
        }
    }
}
 // with extra space
 void permute(vector<int> &container, vector<bool> &visited, vector<int> &num, vector<vector<int> > &result) {
     if(container.size() == num.size()) {
         result.push_back(container);
         return;
     }
     for(int i = 0; i < num.size(); ++i) {
         if(!visited[i]) {
             visited[i] = true;
             container.push_back(num[i]);
             permute(container, visited, num, result);
             visited[i] = false;
             container.pop_back();
         }
     }
 }
Пример #10
0
void permute(int *v, const int start, const int n)
{
   // print(v, n);
	test(v, n);
  if (start < n) {
    int i, j;
    for (i = n-2; i >= start; i--) {
      for (j = i + 1; j < n; j++) {
    swap(v, i, j);
    permute(v, i+1, n);
      } // for j
      rotateLeft(v, i, n);
    } // for i
  }
} // permute
Пример #11
0
void CStreamMerger::primeRows(const void * * rows)
{
    assertex(first && (activeInputs == 0));
    first = false;
    for(unsigned i = 0; i < numInputs; i++)
    {
        if ((pending[i] = rows[i]) != NULL)
        {
            mergeheap[activeInputs++] = i;
            pendingMatches[i] = true;
        }
    }

    permute();
}
Пример #12
0
/* Function to print permutations of string This function takes three parameters:
 1. String
 2. Starting index of the string
 3. Ending index of the string. */
void permute(char *str, int start, int end)
{
 int i;
 if (start == end)
    printf("%s\n", str);
 else
 {
    for (i = start; i <= end; i++)
    {
      swap( (str + start), ( str + i) );
      permute(str, start+1, end);
      swap( (str + start), ( str + i) );                         // swap back to previous condition.
    }
 }
}
Пример #13
0
    void permute(vector<int>& nums,int n, map<int,int> numToCount, vector<vector<int>>& res,vector<int>& perm,int count){
        if(count==n){
            res.push_back(vector<int>(perm));
            return;
        }
        for(map<int,int>::iterator it=numToCount.begin();it!=numToCount.end();++it){
                if(it->second==0) continue;
               perm.push_back(it->first);
               it->second--;
               permute(nums,n,numToCount,res,perm,count+1);
               perm.pop_back();
               it->second++;
           }

    }
Пример #14
0
void permute(int start, int end, char *str) {
	if(start>end) {
		return;
	}
	if(start==end) {
		printf("%s\n",str);
		return;
	}
	int i=start;
	for(;i<=end;i++) {
		swap(str+start, str+i);
		permute(start+1, end, str);
		swap(str+i, str+start);
	}
}
Пример #15
0
    void permute(vector<vector<int>>& ans, vector<int>& perm, int begin)
    {
        if (begin == perm.size()) {
            ans.push_back(perm);
            return;
        }

        for (int i=begin; i<perm.size(); i++) {
            if (i!=begin && perm[i] == perm[begin]) continue;
            swap(perm[i], perm[begin]);
            permute(ans, perm, begin+1);
            swap(perm[i], perm[begin]);
        }

    }
Пример #16
0
void genShapes(int k)
{
  int * array;
  array = malloc(sizeof(int)*k);
  int i=0;
  for(i = 0; i < k; i++)
   {
      array[i] = i;
      //    printf("array[%d] = %d\n", i, array[i]);
    }

  permute(array, k);
  //printf
  return;
}
Пример #17
0
//to generate all the permutation of the keys
void permute(int *a, int i, int n) 
{
	int j;
	if(i==n)
		printArray(a,n);
	else 
	{
	        for (j = i; j <= n; j++) 	
		{
	          swap((a+i), (a+j));
	          permute(a, i+1, n);
	          swap((a+i), (a+j)); 
	       }
	}
}
Пример #18
0
int permute(char *a, int i, int n)
{
  int j;
  if(i==n)
    return a;
  else
    {
      for(j=i;j<=n;j++)
	{
	  swap((a+i), (a+j));
	  permute(a, i+1, n);
	  swap((a+i), (a+j));
	}
    }
}
Пример #19
0
/* Function to print permutations of string
   This function takes three parameters:
   1. String
   2. Starting index of the string
   3. Ending index of the string. */
void permute(char *a, int l, int r)
{
  int i;
  if (l == r)
    printf("%s\n", a);
  else
    {
      for (i = l; i <= r; i++)
        {
          swap((a+l), (a+i));
          permute(a, l+1, r);
          swap((a+l), (a+i)); //backtrack
        }
    }
}
Пример #20
0
void QR_decomposition(double **A, double *gamma, int rows, int columns, int *permutation) {
	int k;
	double t, *norms, *max;
	norms = malloc(columns * sizeof(double));
	max = malloc(columns * sizeof(double));
	for (k = 0; k < columns; k ++) {
		update_norms_vector(A, rows, columns, norms, k, max);
		permute(A, rows, columns, permutation, norms, k);
		t = generating_Q(rows, A, k, gamma, norms);
		update_matrix(A, gamma, rows, columns, k);
		A[k][k] = -t;
	}
	free(max);
	free(norms);
}
/* Function to print permutations of string
   This function takes three parameters:
   1. String
   2. Starting index of the string
   3. Ending index of the string. */
void permute(char *a, int i, int n) 
{
   int j; 
   if (i == n)
     printf("%s\n", a);
   else
   {
        for (j = i; j <= n; j++)
       {
          swap((a+i), (a+j));
          permute(a, i+1, n);
          swap((a+i), (a+j)); //backtrack
       }
   }
} 
Пример #22
0
static unsigned int
transform_blk (void *c, const unsigned char *data)
{
  MD2_CONTEXT *ctx = c;
  int j;

  for (j = 0; j < 16; j++)
    {
      ctx->C[j] ^= S[data[j] ^ ctx->L];
      ctx->L = ctx->C[j];
    }

  permute(ctx->X, data);

  return /* burn stack */ 4 + 5 * sizeof(void*);
}
Пример #23
0
void permute(char res[PERM_LEV+1], int full[PERM_LEV], int level){
	if(level == PERM_LEV){
		res[PERM_LEV] = '\0';
		if(prime(strtol(res, NULL, 10)))
			printf("%s\n",res);
		return;
	}
	for(int i = 0;i < PERM_LEV;i++){
		if(full[i] != 1){
			res[level] = 49 + i;
			full[i] = 1;
			permute(res, full, level + 1);
			full[i] = 0;
		}
	}
}
Пример #24
0
int main()
{
    int n, k, j, y, z;
    int * arr;
    /*scanf("%d %d", &n,&k);*/ k=2;
    for (n=0; n<20; n++)
    {
        int empty[n];
        for (j=0; j<n; j++)
            empty[j] = 0;
        arr = empty;
        z = permute(arr, n, n, k);
        printf("%d\n",z);
    }
    return 0;
}
Пример #25
0
void test02 ( int32_t argc, char * argv[] )
{
    char dig[] = "0123456789";
    uint64_t y = 10*9*8*7*6*5*4*3*2*1;

    g_cnt=0;
    permute(dig,0,10);
    info_print("y     = %llu",y);
    info_print("g_cnt = %llu",g_cnt);

    /*
    memset(d,0,11);
    memcpy(d,dig,k);
    permute(d,0,k);
    */
}
Пример #26
0
void permute(char *str, const int begin, const int end) 
{
  int i = begin;
  int j;
  
  for (i = begin; i < end-1; ++i) 
  {
    for (j = i+1; j < end; ++j) 
    {
       swap(str + i, str + j);
       permute(str, i+1, end);
       swap(str + i, str + j);
    }
  }
  printf("%s\n", str);
}
Пример #27
0
/* permute [set[begin], set[end]) */
int permute(char* set, int begin, int end)
{
    int i;
    int range = end - begin;
    if (range == 1) {
        //printf("set: %s\n", set);
    } else {
        for(i=0; i<range; i++) {
            swap(&set[begin], &set[begin+i]);
            permute(set, begin+1, end);
            swap(&set[begin], &set[begin+i]);       /* set back */
           }
    }
     return 0;

}
Пример #28
0
int main()
{

char *str;
size_t maxchar=20;
int len=0;

getline(&str,&maxchar,stdin);
printf("String entered is:");
puts(str);
len=strlen(str);
permute(str,0,len-1);


return 0;
}
    void permute(string& res, vector<int>& nums, int n, int k) {
    	if(n == 1) {
    		res.push_back(nums[1] + '0');
    		return;
    	}
        int length = 1, tmpn = n;
        tmpn--;
        while(tmpn != 1) {
            length *= tmpn;
            tmpn--;
        }
		int digit = ceil(double(k)/length);
		res.push_back(nums[digit] + '0');
		nums.erase(nums.begin() + digit);
		permute(res, nums, n-1, k-(digit-1)*length);
    }
Пример #30
0
void permute(char * str, int i, int length)
{
    if(i == length)
    {
        printf("%s\n", str);
        return;
    }

    for(int j = i; j < length; j++)
    {
        swap(str + i, str + j);
        permute(str, i + 1, length);
        swap(str + i, str + j);
    }
    return;
}