Exemplo n.º 1
0
void
pqsort(int *lo, int *hi)
{
	if (lo >= hi)
    {
		return;
    }

	int pivot = *lo;	// yeah, bad way to choose pivot...
	int *l = lo+1, *h = hi;
	while (l <= h) {
		if (*l < pivot)
			l++;
		else if (*h > pivot)
			h--;
		else
			swapints(*h, *l), l++, h--;
	}
	swapints(*lo, l[-1]);
	// Now recursively sort the two halves in parallel subprocesses
	if (!dput(0, DET_START | DET_SNAP,0,0,0)) {
		pqsort(lo, l-2);
		dret();
	}
	if (!dput(1, DET_START | DET_SNAP,0,0,0)) {
		pqsort(h+1, hi);
		dret();
	}
    assert(0 < dget(0, DET_MERGE, (unsigned long)randints, sizeof(randints), 0));
    assert(0 < dget(1, DET_MERGE, (unsigned long)randints, sizeof(randints), 0));
	dput(0, DET_KILL, 0, 0, 0);
	dput(1, DET_KILL, 0, 0, 0);
}
Exemplo n.º 2
0
//char *
void
EnDeCrypt(const char *pszText, int iTextLen, const char *pszKey,char *cipher)
/* ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   ;:::  This routine does all the work. Call it both to ENcrypt    :::
   ;:::  and to DEcrypt your data.                                  :::
   ;:::  You MUST free the returned pointer when no longer needed   :::
   ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
{
//    char *cipher = NULL;                /* Output buffer                */
    int a, b, i=0, j=0, k;              /* Ambiguously named counters   */
    int ilen;                           /* Length of a string           */
    int sbox[256];                      /* Encryption array             */
    int key[256];                       /* Numeric key values           */

    ilen = strlen(pszKey);

    for (a=0; a < 256; a++)
    {
        key[a] = pszKey[a % ilen];
        sbox[a] = a;
    }

    for (a=0, b=0; a < 256; a++)
    {
        b = (b + sbox[a] + key[a]) % 256;
        swapints(sbox, a, b);
    }

//    cipher = (char *)malloc(iTextLen * sizeof (char));

    for (a=0; a < iTextLen; a++)
    {
        i = (i + 1) % 256;
        j = (j + sbox[i]) % 256;
        swapints(sbox, i, j);
        k = sbox[(sbox[i] + sbox[j]) % 256];
        cipher[a] = (char)(pszText[a] ^ k);
    }
 //   return cipher;
}
Exemplo n.º 3
0
//RC4
char* EnDeCrypt(const char *pszText, const char *pszKey)
{
    char *cipher;                        
    int a, b, i=0, j=0, k;               
    int ilen;                           
    int iTextLen;						 
    int sbox[256];                                    
    int key[256];                                  

    ilen = strlen(pszKey); 
    iTextLen=strlen(pszText);//ClearTextLength

    for (a=0; a < 256; a++)
    {
        key[a] = pszKey[a % ilen];
        sbox[a] = a;
    }
	
    
    for (a=0, b=0; a < 256; a++)
    {
        b = (b + sbox[a] + key[a]) % 256; 
	swapints(sbox, a, b);

    }
	
    cipher = (char *)malloc(iTextLen);

    for (a=0; a < iTextLen; a++)
    {
        i = (i + 1) % 256;
        j = (j + sbox[i]) % 256;
        swapints(sbox, i, j);
        k = sbox[(sbox[i] + sbox[j]) % 256];
        cipher[a] = pszText[a] ^ k;
    }
    cipher[a]=0;
    return cipher;
Exemplo n.º 4
0
  void filltri(int xa,int ya,int xb,int yb,int xc,int yc,CT c) {

    if (xa>xb) {
      swapints(&xa,&xb); swapints(&ya,&yb);
    }
    if (xb>xc) {
      swapints(&xb,&xc); swapints(&yb,&yc);
    }
    if (xa>xb) {
      swapints(&xa,&xb); swapints(&ya,&yb);
    }
    int start=xa;
    if (xa<0)
      start=0;
    for (int x=start;x<=xb;x++) {
      float xthruab;
      if (xb==xa)
        xthruab=0;
      else
      xthruab=(float)(x-xa)/(xb-xa);
      float xthruac;
      if (xa==xc)
        xthruac=0;
      else
      xthruac=(float)(x-xa)/(xc-xa);
      int ylow=(int)(ya+xthruab*(float)(yb-ya));
      int yhei=(int)(ya+xthruac*(float)(yc-ya));
      if (ylow>yhei) {
        int tmp=yhei;
        yhei=ylow;
        ylow=tmp;
      }
      vline(x,ylow,yhei,c);
    }
    int end=xc;
    for (int x=xb;x<=end;x++) {
      float xthrubc;
      if (xb==xc)
        xthrubc=0;
      else
      xthrubc=(float)(x-xb)/(xc-xb);
      float xthruac;
      if (xa==xc)
        xthruac=0;
      else
      xthruac=(float)(x-xa)/(xc-xa);
      int ylow=(int)(yb+xthrubc*(float)(yc-yb));
      int yhei=(int)(ya+xthruac*(float)(yc-ya));
      if (ylow>yhei) {
        int tmp=yhei;
        yhei=ylow;
        ylow=tmp;
      }
      // System.out.println(x+","+ylow+" - "+yhei);
      // System.out.println("    "+xthruab+" "+xthruac);
      vline(x,ylow,yhei,c);
    }
  }