Esempio n. 1
0
int main(void) {

  //compute the challenge hash
  SHA1((unsigned char *)challenge_string, strlen(challenge_string), &challenge_hash[0]);

  //load words into the dict
  init_dict("words.txt");

  //get ready to read /dev/urandom
  init_random();

  //init 'best'
  top_distance = 5000;

  //compute!
  int nums[NUM_WORDS], i, len, dist;
  char buf[BUF_MAX];
  sha1_hash tmp_hash[SHA_DIGEST_LENGTH];

  while(1) {
    get_nums(nums,NUM_WORDS);
    len = build_string(buf, nums, NUM_WORDS);
    SHA1((unsigned char*)buf, len, tmp_hash);
    dist = distance(challenge_hash, tmp_hash);
    if(dist < top_distance) {
      //we have a winnar (maybe)
      memcpy(top_string, buf, len+1);
      top_distance = dist;
      printf("%i\t\"%s\"\n", top_distance, top_string);
      fflush(stdout);
    }
  }

  return 0;
}
Esempio n. 2
0
get_outputs()
{
	int	i;
	int	j;

	struct	nf	*n;

	char	buf[80];

	get_str(cfp,buf," ");
	/* next line must specify outputs */
	if (strcmp(buf, "output") != 0)
		parse_err();
	get_str(cfp,buf," ");
	if (strcmp(buf, "node") != 0){
		if (strcmp(buf, "nodes") != 0)
			parse_err();
	}
	get_str(cfp,buf," ");
	if (strcmp(buf, "are") != 0){
		if (strcmp(buf, "is") != 0)
		parse_err();
	}
	get_str(cfp,buf,"\n");
	get_nums(buf,nn+ni,ni,selects);
	if (selects[0] == 1){
		fprintf(stderr,"Node 0 cannot be an output\n");
		exit(1);
	}
	for (i = 1; i <= ni; i++){
		if (selects[i] == 1){
			fprintf(stderr,"An input cannot be an output\n");
			exit(1);
		}
	}
	n = ninfo;
	for (i = ni+1, j = -1; i <= nn+ni; i++, n++){
		if (selects[i] > 0){
			if (++j < no){
				outputs[j] = i-ni;
				n->targ = 1;
			}
		}
	}
	if (++j != no){
		fprintf(stderr,"Expecting %d outputs, found %d\n",no,j);
		exit(1);
	}

}
Esempio n. 3
0
get_connections()
{
	int	i;
	int	j;
	int	k;

	struct	cf	*ci;

	int	gn;

	float	min;
	float	max;

	char	buf[80];

	int	*tmp;
	int	*iselects;

	/* malloc space for iselects */
	iselects = (int *) malloc(nt * sizeof(int));
	if (iselects == NULL){
		perror("iselects malloc failed");
		exit(1);
	}

	get_str(cfp,buf,"\n");
	/* next line must be "CONNECTIONS:" */
	if (strcmp(buf, "CONNECTIONS:") != 0)
		parse_err();

	get_str(cfp,buf," ");

	/* next line must be "groups = #" */
	if (strcmp(buf, "groups") != 0)
		parse_err();
	get_str(cfp,buf," ");
	if (buf[0] != '=')
		parse_err();
	get_str(cfp,buf,"\n");
	ngroups = atoi(buf);

	/* malloc space for tmp */
	tmp = (int *) malloc((ngroups+1) * sizeof(int));
	if (tmp == NULL){
		perror("tmp malloc failed");
		exit(1);
	}

	get_str(cfp,buf," ");
	while (strcmp(buf, "SPECIAL:") != 0){
		/* a group is identified */
		if (strcmp(buf,"group") == 0){
			get_str(cfp,buf," ");
			get_nums(buf,ngroups,0,tmp);
			get_str(cfp,buf," ");
			if (buf[0] != '=')
				parse_err();
			get_str(cfp,buf," ");
			/* group * = fixed */
			if (strcmp(buf,"fixed") == 0){
				for (i = 0; i < nn; i++){
					ci = *(cinfo + i);
					for (j = 0; j < nt; j++, ci++){
						if (tmp[ci->num])
							ci->fix = 1;
					}
				}
			}
			/* group * = wmin & wmax */
			else {
				min = (float) atof(buf);
				get_str(cfp,buf," ");
				if (buf[0] != '&')
					parse_err();
				get_str(cfp,buf," ");
				max = (float) atof(buf);
				if (max < min){
					fprintf(stderr,"ERROR: %g < %g\n\n",max,min);
					parse_err();
				}
				for (i = 0; i < nn; i++){
					ci = *(cinfo + i);
					for (j = 0; j < nt; j++, ci++){
						if (tmp[ci->num]){
							limits = 1;
							ci->lim = 1;
							ci->min = min;
							ci->max = max;
						}
					}
				}
			}
			strcat(pbuf,"\n");
			get_str(cfp,buf," ");
		}
		/* a connection is specified */
		else {
			get_nums(buf,nn+ni,ni,selects);
			if (selects[0]){
				fprintf(stderr,"Connecting TO a bias\n\n");
				parse_err();
			}
			for (i = 1; i <= ni; i++){
				if (selects[i]){
					fprintf(stderr,"Connecting TO an input\n\n");
					parse_err();
				}
			}
			get_str(cfp,buf," ");
			if (strcmp(buf,"from") != 0)
				parse_err();
			get_str(cfp,buf," ");
			get_nums(buf,nn+ni,ni,iselects);
			for (i = 0; i < nn; i++){
				ci = *(cinfo + i);
				for (j = 0; j < nt; j++, ci++){
					if ((selects[i+ni+1]) && (iselects[j]))
						ci->con += 1;
				}
			}
			strcat(pbuf,"\t");
			get_str(cfp,buf," ");
			if (buf[0] == '='){
				get_str(cfp,buf," ");
				/* connection  = fixed */
				if (strcmp(buf,"fixed") == 0){
					for (i = 0; i < nn; i++){
						ci = *(cinfo + i);
						for (j = 0; j < nt; j++, ci++){
							if ((selects[i+ni+1]) &&
								(iselects[j]))
								ci->fix = 1;
						}
					}
				}
				else {
				    /* connection  = group # */
				    if (strcmp(buf,"group") == 0){
					get_str(cfp,buf," ");
					gn = atoi(buf);
					for (i = 0; i < nn; i++){
					    ci = *(cinfo + i);
					    for (j = 0; j < nt; j++, ci++){
						if ((selects[i+ni+1]) &&
							(iselects[j]))
							ci->num = gn;
					    }
					}
				    }
				    /* connection  = min & max */
				    else {
					min = (float) atof(buf);
					get_str(cfp,buf," ");
					if (buf[0] != '&')
						parse_err();
					get_str(cfp,buf," ");
					max = (float) atof(buf);
					if (max < min){
						fprintf(stderr,"ERROR: %g < %g\n\n",max,min);
						parse_err();
					}
					for (i = 0; i < nn; i++){
						ci = *(cinfo + i);
						for (j = 0; j < nt; j++, ci++){
							if ((selects[i+ni+1]) &&
								(iselects[j])){
								limits = 1;
								ci->lim = 1;
								ci->min = min;
								ci->max = max;
							}
						}
					}
				    }
				}
				get_str(cfp,buf,"\t");
				if (strcmp(buf,"fixed") == 0){
					for (i = 0; i < nn; i++){
						ci = *(cinfo + i);
						for (j = 0; j < nt; j++, ci++){
							if ((selects[i+ni+1]) &&
								(iselects[j]))
								ci->fix = 1;
						}
					}
					get_str(cfp,buf,"\t");
				}
				if (strcmp(buf,"one-to-one") == 0){
					for (k = 0; k < nt; k++){
						if (iselects[k])
							break;
					}
					for (i = 0; i < nn; i++){
						ci = *(cinfo + i);
						for (j = 0; j < nt; j++, ci++){
							if ((selects[i+ni+1]) &&
								(iselects[j])){
								if (ci->con == 1){
									ci->con = 0;
									ci->fix = 0;
									ci->lim = 0;
								}
								else
									ci->con -= 1;
							}
						}
						if (selects[i+np]){
							ci = *(cinfo + i) + k++;
							ci->con = 1;
							ci->fix = 1;
							ci->lim = 1;
						}
					}
					get_str(cfp,buf,"\n");
				}
			}
		}
	}
/*
	for (i = 0; i < nn; i++){
		ci = *(cinfo + i);
		for (j = 0; j < nt; j++, ci++){
			fprintf(stderr,"i: %d  j: %d  c: %d  f: %d  g: %d\n",
					i,j,ci->con,ci->fix,ci->num);
		}
	}
*/

}
Esempio n. 4
0
get_special()
{
	char	buf[80];
	char	tmp[80];

	int	i;

	int	*iselects;

	struct	nf	*n;

	/* malloc space for iselects */
	iselects = (int *) malloc(nt * sizeof(int));
	if (iselects == NULL){
		perror("iselects malloc failed");
		exit(1);
	}


	while (fscanf(cfp,"%s",buf) != EOF){
	if (strlen(pbuf) > MAX_PARSE_BUF -512) strcpy(pbuf, pbuf +512);
		strcat(pbuf,buf);
		strcat(pbuf," ");
		get_str(cfp,tmp," ");
		if (tmp[0] != '=')
			parse_err();
		get_str(cfp,tmp,"\n");
		if (strcmp(buf,"weight_limit") == 0)
			weight_limit = (float) atof(tmp);
		if (strcmp(buf,"selected") == 0){
			get_nums(tmp,nn,0,selects);
		}
		if (strcmp(buf,"linear") == 0){
			get_nums(tmp,nn,0,iselects);
			n = ninfo;
			for (i = 1; i <= nn; i++, n++){
				if (iselects[i])
					n->func = 2;
			}
		}
		if (strcmp(buf,"bipolar") == 0){
			get_nums(tmp,nn,0,iselects);
			n = ninfo;
			for (i = 1; i <= nn; i++, n++){
				if (iselects[i])
					n->func = 1;
			}
		}
		if (strcmp(buf,"binary") == 0){
			get_nums(tmp,nn,0,iselects);
			n = ninfo;
			for (i = 1; i <= nn; i++, n++){
				if (iselects[i])
					n->func = 3;
			}
		}
		if (strcmp(buf,"delayed") == 0){
			get_nums(tmp,nn,0,iselects);
			n = ninfo;
			for (i = 1; i <= nn; i++, n++){
				if (iselects[i])
					n->dela = 1;
			}
		}
	}

}
Esempio n. 5
0
void report(char *ip, int kill)
{
	int sockfd = open_socket_connection(ip, 1148);
	get_nums(sockfd, kill);
}