Exemplo n.º 1
0
int connectedlink(int nlink)
{
    char buf[400];
    struct socketnodes *lkm;
    int tmpsock;
    pcontext;
    tmpsock=datalink(nlink)->outsock;
    ssnprintf(tmpsock,lngtxt(512),datalink(nlink)->name,socketnode->sock->sport);
    if (*datalink(nlink)->pass==0)
    {
	strmncpy(datalink(nlink)->pass,randstring(15),sizeof(datalink(nlink)->pass));
	writelink(nlink);
    }
    ssnprintf(tmpsock,lngtxt(513),datalink(nlink)->pass);
    ssnprintf(tmpsock,lngtxt(514),me,me);
#ifdef PARTYCHANNEL
    ssnprintf(tmpsock,lngtxt(515));
#endif
#ifdef INTNET
    joinintnettolink(nlink);
#endif
    ssnprintf(tmpsock,lngtxt(516));
    p_log(LOG_INFO,-1,lngtxt(517),
	nlink,datalink(nlink)->host,datalink(nlink)->port);
    return 0x0;
}
Exemplo n.º 2
0
// THE MAIN
main(int argc, char *argv[]) 	// Aufruf: setflag a 'b-.-c' d
{
        char* flag_id = argv[1];        // FahrzeugnummerBeginnWortBeginn
        char* password = argv[2];       // ( komplette Fahrzeugnummer-.-komplettes Wort )
        char* content = argv[3];        // the flag itself

        char delimiter[] = "-.-";
        char *ptr;
        ptr = strtok(password, delimiter);
        char* fzn = ptr;
        printf("fzn: %s\n", fzn);

        ptr = strtok(NULL, delimiter);
        char* bayWord = ptr;
        printf("bayWord: %s\n", bayWord);

	char* aeskey = randstring(256);
	printf("aeskey: %s\n", aeskey);
	encryptString(content, aeskey);

	addBayWordAndKeyToBayCsv(bayWord, aeskey);	//TODO Dateipfad kontrollieren
	addFznAndEncContentToFznCsv(fzn, content);	//TODO Dateipfad kontrollieren


/* RESTE TO DELETE
//	char lineToAdd[1000];
//	sprintf(lineToAdd, "%s;%s", flag_id, content);
//	printf("%s\n", lineToAdd);
//	addStringToFile(lineToAdd, "ba");

/*
	// save flag in file and encrypt file
	FILE *f = fopen("flagfile", "w");
	fprintf(f, "%s", content);

	fclose(f);


	// save flag_id in Fahrzeugnummern.csv
	f = fopen("flag_id_file", "w");
	fprintf(f, "%s", flag_id);


	fclose(f);


	// hash password and save it somewhere
//	char cmd[80];
//	sprintf(cmd, "echo %s | openssl sha1 > pwfile", password);
//	system(cmd);
//	printf("%s", cmd);
RESTE TO DELETE ENDE */
}
Exemplo n.º 3
0
void do_8ball(COMMAND_ARGS)
{
	char	*message;

	if ((message = randstring(RAND8BALLFILE)) == NULL)
	{
		to_user_q(from,ERR_FILEOPEN,RAND8BALLFILE);
		return;
	}

	to_user_q(from,FMT_PLAIN,message);
}
Exemplo n.º 4
0
/*
 *  woo.. no args? we use CurrentChan, CurrentNick and CurrentUser.
 */
void greet(void)
{
	Strp	*sp,**pp;
	char	linebuf[MSGLEN],readbuf[MSGLEN];
	char	*str;
	int	fd,sz;

	pp = &current->sendq;
	while(*pp)
		pp = &(*pp)->next;

	if (CurrentUser->x.x.greetfile)
	{
		if ((fd = open(CurrentUser->greet,O_RDONLY)) < 0)
			return;

		sz = sizeof(Strp) + 9 + strlen(CurrentNick);

		memset(readbuf,0,sizeof(readbuf));
		while(TRUE)
		{
			str = sockread(fd,readbuf,linebuf);
			if (str)
			{
				*pp = sp = (Strp*)Calloc(sz + strlen(str));
				/* Calloc sets to zero sp->next = NULL; */
				pp = &sp->next;
				sprintf(sp->p,"NOTICE %s :%s",CurrentNick,str);
			}
			else
			if (errno != EAGAIN)
				break;
		}

		close(fd);
	}
	else
	if (CurrentUser->x.x.randline)
	{
		if ((str = randstring(CurrentUser->greet)))
			goto single_line;
		return;
	}
	else
	{
		str = CurrentUser->greet;
single_line:
		*pp = sp = (Strp*)Calloc(sizeof(Strp) + 13 + Strlen(CurrentChan->name,CurrentNick,str,NULL));
		sprintf(sp->p,"PRIVMSG %s :[%s] %s",CurrentChan->name,CurrentNick,str);
		/* Calloc sets to zero sp->next = NULL; */
	}
}
Exemplo n.º 5
0
const char* translator(const char* word)
//int main(int argc, char* argv[])
{
	/*if (argc == 3)			Encryption (not needed?)
	{
		if(strcmp(argv[1], "encrypt") == 0)
		{
			char* tmp = malloc(sizeof(char)*2000);
			sprintf(tmp, "openssl aes-256-cbc -in %s -out %s.enc -pass pass:§acf578?#*+-463-{{}av@wer637,,..", argv[2], argv[2]);
			popen(tmp, "w");
			return 0;		
		}
		else if(strcmp(argv[1], "decrypt")==0)
		{*/

		
	char* randName = randstring(15);
	FILE* f = NULL;
	char* tmp = malloc(sizeof(char)*2000);
	char* remove = malloc(sizeof(char)*200);
	sprintf(tmp, "openssl aes-256-cbc -d -in Bayrisch.csv.enc -out %s -pass pass:§acf578?#*+-463-{{}av@wer637,,..", randName);
	f = popen(tmp, "w");
	pclose(f);
	FILE* output=fopen(randName, "r");
	char* encryptedData[1500];
	int i = 0;
	int p = 1;
	char* result = malloc(128);
	memset(result, 0, strlen(result));
	encryptedData[0] = malloc(sizeof(char)*500);
	char line[1024];
	while(fgets(line, 1024, output)!=NULL)
	{
		char* tmp = strdup(line);
		if(strcmp(getfield(tmp, 1), word) == 0)
		{
			strcpy(tmp, line);
			sprintf(result,"The word %s means %s\n", word, getfield(tmp,2));
		}
		sprintf(encryptedData[i], "%s", line); 
		i++;
		encryptedData[i] = malloc(sizeof(char)*500);
		free(tmp);
	}
	if(strlen(result) == 0)
		sprintf(result, "Sorry we couldn't find that word\n");
	/* give result to the next function */
	sprintf(remove, "rm %s", randName);
	popen(remove, "w");
	return result;
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
    char buf[32];
    char buf2[32];
    int i;
    int len;
    hash_t *ht, *htcpy;
    hash_iter_t *iter;

    srand(time(NULL));
    ht = hash_create(16);
    HASH_SET_KEYCPY(ht, _demo_dup);
    HASH_SET_VALCPY(ht, _demo_dup);
    HASH_SET_FREE_KEY(ht, _demo_destructor);
    HASH_SET_FREE_VAL(ht, _demo_destructor);
    HASH_SET_KEYCMP(ht, _demo_cmp);

    for (i = 0; i < 100000; ++i) {
        len = randstring(buf, 1, sizeof(buf) - 1);
        buf[len] = '\0';
        len = randstring(buf2, 1, sizeof(buf2) - 1);
        buf2[len] = '\0';
        hash_insert(ht, buf, buf2);
    }

    hash_dump(ht);
    htcpy = hash_dup(ht);
    hash_free(ht);
    printf("================================\n\n\n");
    iter = hash_iter_new(htcpy);
    assert(iter);

    do {
        printf("%s=>%s\n", (char *)iter->key, (char *)iter->value);
    } while (hash_iter_next(iter) == 0);

    hash_free(htcpy);
    exit(0);
}
/* Print n strings that are hashed to 0 by universal_hash seeded with seed */
void collide_dumb(unsigned int size, unsigned int seed, int n) {
	
	char* zeroHashStrings[n];
	
	int zeroHashCounter = 0 ;
	
	//While we don't have enough random numbers, keep trying strings
	while(zeroHashCounter < n)
	{
		char* string = randstring();
		
		if(universal_hash((unsigned char*)string, size)==0)
		{
			zeroHashStrings[zeroHashCounter]= string;
			zeroHashCounter++;
		}
		
		
	}

	//The number of r values generated is always the maximum string length
	fprintf(stdout, "%d\n", MAXSTRLEN);
	
	//Reinitialize the random number generator to get the values we want
	srand(seed);
	
	
	//Print the r values
	int i;
	for(i = 0 ; i < MAXSTRLEN; i++)
	{
		fprintf( stdout, "%d\n" ,rand()%size);
	}

   
	for(i = 0 ; i < n; i++)
	{
		fprintf( stdout, "%s\n" ,zeroHashStrings[i]);
	}


}
Exemplo n.º 8
0
int main()
{

    int i =0;
    int a[5]= {0,0,0,0,0};
    char *str=NULL;
    int hs =0;

    for(i=0;i<10000;i++)
    {
        str = randstring(5);
        hs = hash(str);
        a[hs-1]++;
        printf("\n hash for %s is %d", str, hs);
        free(str);
        str = NULL;
    }

    for(i=0;i<5;i++)
        printf("\nDistribution of %d is %d", i , a[i]);
}
Exemplo n.º 9
0
int addStringToEnc(char* line)
{
	char* randName = randstring(15);
	FILE* f = NULL;
	char* tmp = malloc(sizeof(char)*2000);
	sprintf(tmp, "openssl aes-256-cbc -d -in Bayrisch.csv.enc -out %s -pass pass:§acf578?#*+-463-{{}av@wer637,,..", randName);
	f = popen(tmp, "w");
	pclose(f);
	FILE* output=fopen(randName, "r");
	addStringToFile(line, "ba", randName);
	free(tmp);
	char* tmp2 = malloc(sizeof(char)*2000);
	sprintf(tmp2, "openssl aes-256-cbc -in %s -out Bayrisch.csv.enc -pass pass:§acf578?#*+-463-{{}av@wer637,,..", randName);
	popen(tmp2, "w");
	free(tmp2);
	sleep(1);
	char* remove = malloc(sizeof(char)*200);
	sprintf(remove, "rm %s", randName);
	popen(remove, "w");
	printf("remove cmd: %s\n", remove);
	return 0;	
}
Exemplo n.º 10
0
void do_random_msg(COMMAND_ARGS)
{
	char	*filename,*message;

	filename =  CurrentCmd->cmdarg;

	if (*rest)
	{
		to = chop(&rest);
		if (ischannel(to) && (get_authaccess(from,to) < cmdaccess))
			return;
	}
	else
	if (!ischannel(to))
	{
		usage(from);	/* usage for CurrentCmd->name */
		return;
	}

	if ((message = randstring(filename)) == NULL)
	{
		to_user(from,ERR_FILEOPEN,filename);
		return;
	}

	/*
	 *  send message to target nick/channel
	 */
	to_server("PRIVMSG %s :%s\n",to,message);
	/*
	 *  if its not a channel we send a copy to the user who did the command also
	 */
	if (!ischannel(to))
	{
		to_user(from,"(%s) %s",to,message);
	}
}
Exemplo n.º 11
0
void		ftp_rsauser(t_client *client, char *str)
{
  char		*arg;
  char		filename[4096];
  char		trame[4096];
  unsigned char	encrypted[4096];
  unsigned char	*randstr;
  int		len;

  arg = get_cmd(str, 7);
  if (atoi(client->server->conf->ssl_enabled) == 0 ||
      atoi(client->server->conf->ssl_fconnect) == 0)
    return (ssl_not_actived(client));
  sprintf(filename, "/etc/bertomzilla/.rsa/%s.pub", arg);
  if (!fill_publicKeyFromScratch(client, filename))
    return (show_error("Error while filling RSA File"));
  randstr = randstring(16);
  len = public_encrypt(randstr, 16, client->publicKeyRSA, encrypted);
  post(trame, len, client, encrypted);
  if (!strncmp(trame, (const char*) randstr, 16))
    process_ok(client, arg);
  else
    write(client->fd, "KO\r\n", 4);
}
Exemplo n.º 12
0
void do_randtopic(COMMAND_ARGS)
{
	/*
	 *  on_msg checks CAXS
	 */
	Chan	*chan = CurrentChan;
	char	*topic;

	/*
	 *  the bot can set a random topic if chanmode is -t
	 */
	if (chan->bot_is_op || chan->topprot == FALSE)
	{
		if ((topic = randstring(RANDTOPICSFILE)) == NULL)
		{
			to_user(from,ERR_FILEOPEN,RANDTOPICSFILE);
			return;
		}
		to_server("TOPIC %s :%s\n",to,topic);
		to_user(from,TEXT_TOPICCHANGED,to);
		return;
	}
	to_user(from,ERR_NOTOPPED,to);
}
Exemplo n.º 13
0
int 
main(int argc, char *argv[])
{
    unsigned char *zl, *p;
    unsigned char *entry;
    unsigned int elen;
    long long value;

    /* If an argument is given, use it as the random seed. */
    if (argc == 2)
        srand(atoi(argv[1]));

    zl = createIntList();
    ziplistRepr(zl);

    zl = createList();
    ziplistRepr(zl);

    pop(zl,ZIPLIST_TAIL);
    ziplistRepr(zl);

    pop(zl,ZIPLIST_HEAD);
    ziplistRepr(zl);

    pop(zl,ZIPLIST_TAIL);
    ziplistRepr(zl);

    pop(zl,ZIPLIST_TAIL);
    ziplistRepr(zl);

    printf("Get element at index 3:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, 3);
        if (!ziplistGet(p, &entry, &elen, &value)) {
            printf("ERROR: Could not access index 3\n");
            return 1;
        }
        if (entry) {
            if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            printf("\n");
        } else {
            printf("%lld\n", value);
        }
        printf("\n");
    }

    printf("Get element at index 4 (out of range):\n");
    {
        zl = createList();
        p = ziplistIndex(zl, 4);
        if (p == NULL) {
            printf("No entry\n");
        } else {
            printf("ERROR: Out of range index should return NULL, returned offset: %ld\n", p-zl);
            return 1;
        }
        printf("\n");
    }

    printf("Get element at index -1 (last element):\n");
    {
        zl = createList();
        p = ziplistIndex(zl, -1);
        if (!ziplistGet(p, &entry, &elen, &value)) {
            printf("ERROR: Could not access index -1\n");
            return 1;
        }
        if (entry) {
            if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            printf("\n");
        } else {
            printf("%lld\n", value);
        }
        printf("\n");
    }

    printf("Get element at index -4 (first element):\n");
    {
        zl = createList();
        p = ziplistIndex(zl, -4);
        if (!ziplistGet(p, &entry, &elen, &value)) {
            printf("ERROR: Could not access index -4\n");
            return 1;
        }
        if (entry) {
            if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            printf("\n");
        } else {
            printf("%lld\n", value);
        }
        printf("\n");
    }

    printf("Get element at index -5 (reverse out of range):\n");
    {
        zl = createList();
        p = ziplistIndex(zl, -5);
        if (p == NULL) {
            printf("No entry\n");
        } else {
            printf("ERROR: Out of range index should return NULL, returned offset: %ld\n", p-zl);
            return 1;
        }
        printf("\n");
    }

    printf("Iterate list from 0 to end:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, 0);
        while (ziplistGet(p, &entry, &elen, &value)) {
            printf("Entry: ");
            if (entry) {
                if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            } else {
                printf("%lld", value);
            }
            p = ziplistNext(zl,p);
            printf("\n");
        }
        printf("\n");
    }

    printf("Iterate list from 1 to end:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, 1);
        while (ziplistGet(p, &entry, &elen, &value)) {
            printf("Entry: ");
            if (entry) {
                if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            } else {
                printf("%lld", value);
            }
            p = ziplistNext(zl,p);
            printf("\n");
        }
        printf("\n");
    }

    printf("Iterate list from 2 to end:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, 2);
        while (ziplistGet(p, &entry, &elen, &value)) {
            printf("Entry: ");
            if (entry) {
                if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            } else {
                printf("%lld", value);
            }
            p = ziplistNext(zl,p);
            printf("\n");
        }
        printf("\n");
    }

    printf("Iterate starting out of range:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, 4);
        if (!ziplistGet(p, &entry, &elen, &value)) {
            printf("No entry\n");
        } else {
            printf("ERROR\n");
        }
        printf("\n");
    }

    printf("Iterate from back to front:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, -1);
        while (ziplistGet(p, &entry, &elen, &value)) {
            printf("Entry: ");
            if (entry) {
                if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            } else {
                printf("%lld", value);
            }
            p = ziplistPrev(zl,p);
            printf("\n");
        }
        printf("\n");
    }

    printf("Iterate from back to front, deleting all items:\n");
    {
        zl = createList();
        p = ziplistIndex(zl, -1);
        while (ziplistGet(p, &entry, &elen, &value)) {
            printf("Entry: ");
            if (entry) {
                if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");
            } else {
                printf("%lld", value);
            }
            zl = ziplistDelete(zl,&p);
            p = ziplistPrev(zl,p);
            printf("\n");
        }
        printf("\n");
    }

    printf("Delete inclusive range 0,0:\n");
    {
        zl = createList();
        zl = ziplistDeleteRange(zl, 0, 1);
        ziplistRepr(zl);
    }

    printf("Delete inclusive range 0,1:\n");
    {
        zl = createList();
        zl = ziplistDeleteRange(zl, 0, 2);
        ziplistRepr(zl);
    }

    printf("Delete inclusive range 1,2:\n");
    {
        zl = createList();
        zl = ziplistDeleteRange(zl, 1, 2);
        ziplistRepr(zl);
    }

    printf("Delete with start index out of range:\n");
    {
        zl = createList();
        zl = ziplistDeleteRange(zl, 5, 1);
        ziplistRepr(zl);
    }

    printf("Delete with num overflow:\n");
    {
        zl = createList();
        zl = ziplistDeleteRange(zl, 1, 5);
        ziplistRepr(zl);
    }

    printf("Delete foo while iterating:\n");
    {
        zl = createList();
        p = ziplistIndex(zl,0);
        while (ziplistGet(p,&entry,&elen,&value)) {
            if (entry && strncmp("foo",(char*)entry,elen) == 0) {
                printf("Delete foo\n");
                zl = ziplistDelete(zl,&p);
            } else {
                printf("Entry: ");
                if (entry) {
                    if (elen && fwrite(entry,elen,1,stdout) == 0)
                        perror("fwrite");
                } else {
                    printf("%lld",value);
                }
                p = ziplistNext(zl,p);
                printf("\n");
            }
        }
        printf("\n");
        ziplistRepr(zl);
    }

    printf("Regression test for >255 byte strings:\n");
    {
        char v1[257],v2[257];
        memset(v1,'x',256);
        memset(v2,'y',256);
        zl = ziplistNew();
        zl = ziplistPush(zl,(unsigned char*)v1,strlen(v1),ZIPLIST_TAIL);
        zl = ziplistPush(zl,(unsigned char*)v2,strlen(v2),ZIPLIST_TAIL);

        /* Pop values again and compare their value. */
        p = ziplistIndex(zl,0);
        assert(ziplistGet(p,&entry,&elen,&value));
        assert(strncmp(v1,(char*)entry,elen) == 0);
        p = ziplistIndex(zl,1);
        assert(ziplistGet(p,&entry,&elen,&value));
        assert(strncmp(v2,(char*)entry,elen) == 0);
        printf("SUCCESS\n\n");
    }

    printf("Regression test deleting next to last entries:\n");
    {
        char v[3][257];
        zlentry e[3];
        int i;

        for (i = 0; i < (sizeof(v)/sizeof(v[0])); i++) {
            memset(v[i], 'a' + i, sizeof(v[0]));
        }

        v[0][256] = '\0';
        v[1][  1] = '\0';
        v[2][256] = '\0';

        zl = ziplistNew();
        for (i = 0; i < (sizeof(v)/sizeof(v[0])); i++) {
            zl = ziplistPush(zl, (unsigned char *) v[i], strlen(v[i]), ZIPLIST_TAIL);
        }

        verify(zl, e);

        assert(e[0].prevrawlensize == 1);
        assert(e[1].prevrawlensize == 5);
        assert(e[2].prevrawlensize == 1);

        /* Deleting entry 1 will increase `prevrawlensize` for entry 2 */
        unsigned char *p = e[1].p;
        zl = ziplistDelete(zl, &p);

        verify(zl, e);

        assert(e[0].prevrawlensize == 1);
        assert(e[1].prevrawlensize == 5);

        printf("SUCCESS\n\n");
    }

    printf("Create long list and check indices:\n");
    {
        zl = ziplistNew();
        char buf[32];
        int i,len;
        for (i = 0; i < 1000; i++) {
            len = sprintf(buf,"%d",i);
            zl = ziplistPush(zl,(unsigned char*)buf,len,ZIPLIST_TAIL);
        }
        for (i = 0; i < 1000; i++) {
            p = ziplistIndex(zl,i);
            assert(ziplistGet(p,NULL,NULL,&value));
            assert(i == value);

            p = ziplistIndex(zl,-i-1);
            assert(ziplistGet(p,NULL,NULL,&value));
            assert(999-i == value);
        }
        printf("SUCCESS\n\n");
    }

    printf("Compare strings with ziplist entries:\n");
    {
        zl = createList();
        p = ziplistIndex(zl,0);
        if (!ziplistCompare(p,(unsigned char*)"hello",5)) {
            printf("ERROR: not \"hello\"\n");
            return 1;
        }
        if (ziplistCompare(p,(unsigned char*)"hella",5)) {
            printf("ERROR: \"hella\"\n");
            return 1;
        }

        p = ziplistIndex(zl,3);
        if (!ziplistCompare(p,(unsigned char*)"1024",4)) {
            printf("ERROR: not \"1024\"\n");
            return 1;
        }
        if (ziplistCompare(p,(unsigned char*)"1025",4)) {
            printf("ERROR: \"1025\"\n");
            return 1;
        }
        printf("SUCCESS\n\n");
    }

    printf("Stress with random payloads of different encoding:\n");
    {
        int i,j,len,where;
        unsigned char *p;
        char buf[1024];
        int buflen;
        list *ref;
        listNode *refnode;

        /* Hold temp vars from ziplist */
        unsigned char *sstr;
        unsigned int slen;
        long long sval;

        for (i = 0; i < 20000; i++) {
            zl = ziplistNew();
            ref = listCreate();
            listSetFreeMethod(ref, sdsfree);
            len = rand() % 256;

            /* Create lists */
            for (j = 0; j < len; j++) {
                where = (rand() & 1) ? ZIPLIST_HEAD : ZIPLIST_TAIL;
                if (rand() % 2) {
                    buflen = randstring(buf,1,sizeof(buf)-1);
                } else {
                    switch(rand() % 3) {
                    case 0:
                        buflen = sprintf(buf,"%lld",(0LL + rand()) >> 20);
                        break;
                    case 1:
                        buflen = sprintf(buf,"%lld",(0LL + rand()));
                        break;
                    case 2:
                        buflen = sprintf(buf,"%lld",(0LL + rand()) << 20);
                        break;
                    default:
                        assert(NULL);
                    }
                }

                /* Add to ziplist */
                zl = ziplistPush(zl, (unsigned char*)buf, buflen, where);

                /* Add to reference list */
                if (where == ZIPLIST_HEAD) {
                    listAddNodeHead(ref,sdsnewlen(buf, buflen));
                } else if (where == ZIPLIST_TAIL) {
                    listAddNodeTail(ref,sdsnewlen(buf, buflen));
                } else {
                    assert(NULL);
                }
            }

            assert(listLength(ref) == ziplistLen(zl));
            for (j = 0; j < len; j++) {
                /* Naive way to get elements, but similar to the stresser
                 * executed from the Tcl test suite. */
                p = ziplistIndex(zl,j);
                refnode = listIndex(ref,j);

                assert(ziplistGet(p,&sstr,&slen,&sval));
                if (sstr == NULL) {
                    buflen = sprintf(buf,"%lld",sval);
                } else {
                    buflen = slen;
                    memcpy(buf,sstr,buflen);
                    buf[buflen] = '\0';
                }
                assert(memcmp(buf,listNodeValue(refnode),buflen) == 0);
            }
            zfree(zl);
            listRelease(ref);
        }
        printf("SUCCESS\n\n");
    }

    printf("Stress with variable ziplist size:\n");
    {
        stress(ZIPLIST_HEAD,100000,16384,256);
        stress(ZIPLIST_TAIL,100000,16384,256);
    }

    return 0;
}
Exemplo n.º 14
0
int main()
{
    node *Table[MAX];
    clearTable(Table);
    int a[MAX];
    char *str;
    /*char in;
    char input[CHARS];*/
    int i, j;
    double t;
    clock_t t1,t2;
    t1=clock();
    for (j=0;j<MAX;j++)
    {
        a[j]=0;
    }
    for (j=0; j<2000; j++)
    {
        str=randstring(CHARS);
        insertValue(Table[hashFunction(str)], str);
        a[hashFunction(str)]++;
    }
    t2=clock();
    t=(double)(t2-t1);
    printf ("The insertion of 2000 elements took %f seconds.", &t);
    printf ("\n");
    for (j=0; j<MAX; j++)
    {
        printf ("%d ", a[j]);
    }

    /*while(1)
    {
        printf("(I)nsert\n(S)earch\n(L)ist all\n\n");
        printf(" > ");
        scanf("%d",&in);
        switch(in)
        {
            case 1:
                printf("\tInserting: \n");
                printf("\t > "); scanf("%s",input);
                Table[hashFunction(input)] = insertValue(Table[hashFunction(input)],input);
                break;
            case 2:
                printf("\tSearching value: \n");
                printf("\t > "); scanf("%s", &input);
                if (hasValue(Table[hashFunction(input)],input))
                {
                    printf("%s is in the table!\n",input);
                }
                else
                {
                    printf("%s is not in the table!\n",input);
                }
                break;
            case 3:
                for (i = 0; i < MAX; i++)
                {
                    printf("[%d] ",i);
                    printList(Table[i]);
                }
                break;
            default:
                break; return;
        }
        printf("_______________________________________________________\n");
    }*/
}
Exemplo n.º 15
0
// THE MAIN
char* main(int argc, char *argv[])
// param options:
// decrypt some aes encrypted string:			enc_string key
// set a new flag d with id=a and token='b-.-c':	a 'b-.-c' d
// add a new fzn with value:				fzn value
{
    if (strcmp(argv[1], "-h") == 0) {	// decryption not really needed but management want me to leave it...
        char* encrypted_flag = argv[2];
        char* aeskey = argv[3];

        char tmpstr[8096];
        sprintf(tmpstr, "echo %s | openssl enc -d -aes-256-cbc -a -k %s", encrypted_flag, aeskey);

        FILE *fp;
        int status;
        char path[4096];
        char content[4096];

        fp = popen(tmpstr, "r");

        if (fp == NULL)
            /* Handle error */;

        fgets(path, 4096, fp);
        sprintf(content, "%s", path);
        if (strlen(content) < 5) {
            printf("gcry_cipher_decrypt failed:");
        } else {
            printf("%s\n", content);
        }
        // dec: echo U2FsdGVkX18eaVlEUPTR47GFaEoh3u9DMHgqvtZS1Ko= | openssl enc -d -aes-256-cbc -a -k mykey
    }
    else if (strcmp(argv[1], "-h") == 0) {	// decryption not really needed but management want me to leave it...
        char* encrypted_flag = argv[2];
        char* aes_key = argv[3];
        //printf("encrypted_flag: %s (%i)\n", encrypted_flag, (int)(strlen(encrypted_flag)));
        char* ascii_flag = hexToString(encrypted_flag);
        //printf("ascii_flag: %s (%i)\n", ascii_flag, (int)(strlen(ascii_flag)));
        decryptString2(ascii_flag, aes_key);
        //printf("passing ascii_flag: %s (%i)\n", ascii_flag, (int)(strlen(ascii_flag)));
        remPad(ascii_flag, strlen(ascii_flag));
        //printf("%s\n", ascii_flag);
        //printf("ascii_flag: %s (%i)\n", ascii_flag, (int)(strlen(ascii_flag)));
        printf("%s\n", ascii_flag);
        return ascii_flag;	// is decryped
    } else if (argc == 4)
    {
        char* flag_id = argv[1];        // FahrzeugnummerBeginnWortBeginn
        char* password = argv[2];       // ( komplette Fahrzeugnummer-.-komplettes Wort )
        char* content_arg = argv[3];        // the flag itself
        char content[4096];

        strcpy(content, content_arg);
        char delimiter[] = "-.-";
        char *ptr;
        ptr = strtok(password, delimiter);
        char* fzn = ptr;

        ptr = strtok(NULL, delimiter);
        char* bayWord = ptr;

        char* aeskey = randstring(16);
        printf("%s\n", aeskey);
        char hex_content[4096];

        char tmpstr[8096];
        sprintf(tmpstr, "echo %s | openssl enc -e -aes-256-cbc -a -k %s", argv[3], aeskey);

        FILE *fp;
        int status;
        char path[4096];

        fp = popen(tmpstr, "r");

        if (fp == NULL)
            /* Handle error */;

        fgets(path, 4096, fp);
        sprintf(hex_content, "%s", path);
        // dec: echo U2FsdGVkX18eaVlEUPTR47GFaEoh3u9DMHgqvtZS1Ko= | openssl enc -d -aes-256-cbc -a -k mykey
//		printf("hex: ||%s||", hex_content);
//		printf("aes: ||%s||", aeskey);
//		printf("-----------");

        printf("fzn: %s\n", fzn);
        printf("bayWord: %s\n", bayWord);
        printf("encrypted: %s\n", hex_content);
        printf("aeskey: %s\n", aeskey);

        // ADD TO FILES
        addFznAndEncContentToFznCsv(fzn, hex_content);
//                printf("Alles3: ||%s|| ; ||%s|| ; ||%s|| ; ||%s|| ; ||%s||\n", bayWord, aeskey, fzn, hex_content, aeskey);
        addBayWordAndKeyToBayCsv(bayWord, aeskey);
//                printf("Alles4: ||%s|| ; ||%s|| ; ||%s|| ; ./setflag -h %s %s\n", bayWord, aeskey, fzn, hex_content, aeskey);


    }
    else if (argc == 4) {	// for managers only!!11
        int done = 0;
        int tries = 0;

        char* flag_id = argv[1];        // FahrzeugnummerBeginnWortBeginn
        char* password = argv[2];       // ( komplette Fahrzeugnummer-.-komplettes Wort )
        char* content_arg = argv[3];        // the flag itself
        char content[4096];

        strcpy(content, content_arg);
        printf("content_arg: %s (%i)\n", content_arg, (int)(strlen(content_arg)));
        printf("Alles::content: %s (%i)\n", content, (int)(strlen(content)));
        printf("content1: %s\n", content);
        char delimiter[] = "-.-";
        char *ptr;
        ptr = strtok(password, delimiter);
        char* fzn = ptr;
        printf("fzn: %s\n", fzn);

        ptr = strtok(NULL, delimiter);
        char* bayWord = ptr;
        printf("Alles::bayWord: %s\n", bayWord);

        char aeskey[1024];
        char hex_content[4096];

        while (done == 0) {		// some weird workaround...
            tries++;
            strcpy(content, content_arg);

            printf("Alles0: || %i ||%s (%i)|| ; ||%s(%i)|| ; ||%s(%i)|| ; ||%s(%i)|| ; ||%s(%i)||\n", tries, bayWord, (int)(strlen(bayWord)), aeskey,(int)(strlen(aeskey)), fzn, (int)(strlen(fzn)), hex_content, (int)(strlen(hex_content)), content, (int)(strlen(content)));
//		char* aeskey = randstring(16);
            strcpy(aeskey, randstring(16));
            printf("aeskey: ||%s||\n", aeskey);
            printf("passing content: %s (%i)\n", content, (int)(strlen(content)));
            addPad(content, sizeof(content));
            printf("AllesX: || %i ||%s (%i)|| ; ||%s(%i)|| ; ||%s(%i)|| ; ||%s(%i)||; ||%s(%i)||\n", tries, bayWord, (int)(strlen(bayWord)), aeskey,(int)(strlen(aeskey)), fzn, (int)(strlen(fzn)), hex_content, (int)(strlen(hex_content)), content, (int)(strlen(content)));
            printf("after addpad: %s (%i)\n", content, (int)(strlen(content)));

            int index = 0;
            printf("AllesS: ");
            for (index = 0; index<strlen(content)+1; index++) {
                printf("%02X", (unsigned char)content[index]);
            }
            printf("\n");

            encryptString2(content, aeskey);
            printf("AllesY: || %i ||%s (%i)|| ; ||%s(%i)|| ; ||%s(%i)|| ; ||%s(%i)||; ||%s(%i)||\n", tries, bayWord, (int)(strlen(bayWord)), aeskey,(int)(strlen(aeskey)), fzn, (int)(strlen(fzn)), hex_content, (int)(strlen(hex_content)), content, (int)(strlen(content)));
            printf("after enc: %s (%i)\n", content, (int)(strlen(content)));
            if (strlen(content) < 32) {
                printf("strlen %i\n", (int)(strlen(content)));
                int rofl = 0;
                printf("As s: ||");
                for (rofl = 0; rofl < 32; rofl++)
                {
                    printf("%c", content[rofl]);
                }
                printf("||\nAs x02: ||");
                for (rofl = 0; rofl < 32; rofl = rofl+2) {
                    printf("%02X", content[rofl]);
                }
                printf("||\n");
            }
            printAsHex(content);
//		char* hex_content = stringToHex(content);
            strcpy(hex_content, stringToHex(content));
            printf("after hex: %s (%i)\n", content, (int)(sizeof(content)));
            printf("Alles1: || %i ||%s (%i)|| ; ||%s(%i)|| ; ||%s(%i)|| ; ||%s(%i)||; ||%s(%i)||\n", tries, bayWord, (int)(strlen(bayWord)), aeskey,(int)(strlen(aeskey)), fzn, (int)(strlen(fzn)), hex_content, (int)(strlen(hex_content)), content, (int)(strlen(content)));

            if ((( strlen(hex_content) > 0 && strlen(content) > 0 && (strlen(hex_content) % 16) == 0 && (strlen(content) % 16) == 0) ) || tries > 4 ) {
                done = 1;
                printf("Alles2: || %i ||%s|| ; ||%s|| ; ||%s|| ; ||%s|| ; ||%s||\n", tries, bayWord, aeskey, fzn, hex_content, aeskey);
                addFznAndEncContentToFznCsv(fzn, hex_content);
                printf("Alles3: || %i ||%s|| ; ||%s|| ; ||%s|| ; ||%s|| ; ||%s||\n", tries, bayWord, aeskey, fzn, hex_content, aeskey);
                addBayWordAndKeyToBayCsv(bayWord, aeskey);
                printf("Alles4: || %i ||%s|| ; ||%s|| ; ||%s|| ; ./setflag -h %s %s\n", tries, bayWord, aeskey, fzn, hex_content, aeskey);
            }
//		char tmpstr[8096];
//		sprintf(tmpstr, "echo 'tries: %i || done: %i || strlen content: (%i) || hex_content: %s (%i) || content_arg: %s (%i) || ' >> setflaglog.log", tries, done, (int)(strlen(content)), hex_content, (int)(strlen(hex_content)), content_arg, (int)(strlen(content_arg)));
//		popen(tmpstr, "r");

        }
    } else {	// official functionality
        char* fzn = argv[1];
        char* value = argv[2];
        if (fzn != NULL && value != NULL) {
            addFznAndEncContentToFznCsv(fzn, value);
            printf("FZN ADDED\n");
        } else {
            printf("you have to provide fzn and value\n");
        }
    }
}