当前位置: 首页>>代码示例>>C++>>正文


C++ mpz_set_str函数代码示例

本文整理汇总了C++中mpz_set_str函数的典型用法代码示例。如果您正苦于以下问题:C++ mpz_set_str函数的具体用法?C++ mpz_set_str怎么用?C++ mpz_set_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mpz_set_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: openSSLGenTest

/* Generate random moduli and check gcd */
int openSSLGenTest(mpz_t *n)
{
	mpz_t myN, genN, tmp;
	long counter = 0;
	int status = FAIL;

	printf("[INFO ] Trying OpenSSL generating\n");

	mpz_init_set(myN, *n);	mpz_init(genN);		mpz_init(tmp);

	BIGNUM *e = NULL;
	RSA *rsa = NULL;

	rsa = RSA_new();
	e = BN_new();
	BN_set_word(e, OPENSSLGENEXPONENT);

	while (counter < OPENSSLGENMAX)
	{

		if (RSA_generate_key_ex(rsa, OPENSSLGENBITS, e, NULL) == 0)
			break;

		mpz_set_str(genN, BN_bn2dec(rsa->n), 10);

		mpz_gcd(tmp, myN, genN);

		if (mpz_cmp_ui(tmp, 1) != 0)
		{
			printWin(&tmp, "OpenSSL gen");
			status = WIN;
			break;
		}

		counter += 1;
	}


	BN_free(e);
	RSA_free(rsa);

	mpz_clear(myN);		mpz_clear(genN);

	return status;
}
开发者ID:DutchGraa,项目名称:LazyfactPython,代码行数:46,代码来源:methodOpenSSLGen.c

示例2: get_cert_exponent

/* Return the public key exponent given the decrypted certificate as string. */
void
get_cert_exponent(mpz_t result, char *cert)
{
	char *srch, *srch2;
	char exponent[RSA_MAX_LEN/2];
	memset(exponent, 0, RSA_MAX_LEN/2);
	srch = strchr(cert, '\n');
	srch += 1;
	srch = strchr(srch, '\n');
	srch += 1;
	srch = strchr(srch, '\n');
	srch += 1;
	srch = strchr(srch, ':');
	srch += 2;
	srch2 = strchr(srch, '\n');
	strncpy(exponent, srch, srch2-srch);
	mpz_set_str(result, exponent, 0);
}
开发者ID:Garyguo2011,项目名称:TLS-Implementation,代码行数:19,代码来源:client_test.c

示例3: compute

int compute(struct In* input, struct Out* output){
  mpz_t a, b, c;
  mpz_init(a);
  mpz_init(b);
  mpz_init(c);
  mpz_set_si(a, input->data[0]);
  //mpz_set_si(b, input->data[1]);
  mpz_set_str(b,
  "2102938470192837410982374019283471029837401298347120984710298347109283471029847102983741029384710293841023874601892364018236409182634098126304816203948612093461029386401928364019286340918263049182630941862039486120394861209348610293846102938461092836401928364019283460192836409132861029837410928374019283741092837410928371092837401298374019823740192837401982374019283740192837401923874102938740192837410928374109283471092387401928374109238741092384710923874102938741092387401298374019283740192837401928374019283741029387410293874102938471209384710923874019283741092837401923874102983740192387410983874019283740923874829581123948653282398625", 10);
  //mpz_add(c, a, b);
  mpz_mul(c, a, b);
  //mpz_sub(c, c, c);
  //mpz_neg(c, c);
  mpz_set(output->b, c);
  mpz_clear(a);
  mpz_clear(b);
  mpz_clear(c);
}
开发者ID:PickXu,项目名称:pantry,代码行数:18,代码来源:gmp_test.c

示例4: main

gint
main()
{
    //gint i = 11;
    mpz_t i, power, sum;
    gint count = 0;
    gint j;
    GPtrArray *special;
    gchar *foo, *bar, *baz;

    mpz_init_set_ui(i, 11);
    mpz_init(power);
    mpz_init(sum);

    special = g_ptr_array_new();

    while(special->len < 30)
    {

        baz = mpz_get_str(NULL, 10, i);
        foo = add_digits_str(baz);
        mpz_set_str(sum, foo, 10);
        free(foo);
        free(baz);
        for(j = 1; j <= 100; j++)
        {
            mpz_pow_ui(power, sum, j);
            if(mpz_cmp(power, i) > 0)
                break;
            if(mpz_cmp(power, i) == 0)
            {
                bar = mpz_get_str(NULL, 10, i);
                g_ptr_array_add(special, bar);
                g_print("%d: %s\t%d\n", special->len, bar, j);
                free(bar);
            }
        }
        mpz_add_ui(i, i, 1);
    }
    mpz_clear(i);
    printf("%s\n", g_ptr_array_index(special, special->len-1));
    g_ptr_array_free(special, TRUE);
    return 0;
}
开发者ID:dougsko,项目名称:projecteuler.net,代码行数:44,代码来源:solution.c

示例5: hec_inc

static PyObject *
hec_inc (PyObject *self, PyObject *args)
{
    const char* s_in;
    unsigned long i_inc;
    if (!PyArg_ParseTuple(args, "sk", &s_in, &i_inc))
        return NULL;

    mpz_t v_in, v_out;
    mpz_init (v_in);
    mpz_init (v_out);
    mpz_set_str (v_in, s_in, 10);
    _hec_inc (v_out, v_in, i_inc);
    const char* s_val = mpz_get_str (NULL, 10, v_out);
    mpz_clear (v_in);
    mpz_clear (v_out);
        
    return Py_BuildValue ("s", s_val);
}
开发者ID:fason,项目名称:stigmergy,代码行数:19,代码来源:hec.c

示例6: rsa_random_integer

void rsa_random_integer(MP_INT *ret, RandomState *state, unsigned int bits)

{

  unsigned int bytes = (bits + 7) / 8;

  char *str = xmalloc(bytes * 2 + 1);

  unsigned int i;



  /* We first create a random hex number of the desired size, and then

     convert it to a mp-int. */

  for (i = 0; i < bytes; i++)

    sprintf(str + 2 * i, "%02x", random_get_byte(state));



  /* Convert it to the internal representation. */

  if (mpz_set_str(ret, str, 16) < 0)

    fatal("Intenal error, mpz_set_str returned error");



  /* Clear extra data. */

  memset(str, 0, 2 * bytes);

  xfree(str);



  /* Reduce it to the desired number of bits. */

  mpz_mod_2exp(ret, ret, bits);

}
开发者ID:dreamsxin,项目名称:ultimatepp,代码行数:43,代码来源:rsa.cpp

示例7: bbs_pseudo_cvt_bytes_to_mpz

// create an mpz_t from a char array of size array_cnt
static void bbs_pseudo_cvt_bytes_to_mpz ( unsigned char *array, int array_cnt , mpz_t result )
{
  char *v_buf;
  char *c;
  int i;

  c = v_buf = alloca ( array_cnt*2 + 1 );
  v_buf [ array_cnt*2 ] = 0;

  for ( i = array_cnt - 1 ; i >= 0 ; i--, c += 2 ) {
    sprintf(c,"%02x",array[i]&0xff);
  }

#if 0 && defined(CP_TEST)
  printf("%s\n",v_buf);
#endif

  mpz_set_str(result,v_buf,16);
}
开发者ID:cpsource,项目名称:dibit,代码行数:20,代码来源:bbs_pseudo.c

示例8: first_test

int first_test(mpz_t n){

	int test = 1;
	int sortie = 0;
	mpz_t nb, max,mod;

       	mpz_init (nb);
       	mpz_init (max);
	mpz_init (mod);

	mpz_root(max, n, 2); //need debug
	//gmp_printf ("\nDebug racine carré : %Zd\n", max);
	//mpz_out_str(stdout, 10, max);

	mpz_set_str(nb,"2",10);
	//gmp_printf ("\nDebug compteur : %Zd\n", nb);

	if(mpz_cmp_si(n,0)== 0 || mpz_cmp_si(n,1)== 0){
		test = 0;
		sortie = 1;
	}

	for(sortie = 0;sortie!=1 && mpz_cmp(nb,max)<=0;mpz_add_ui(nb,nb,1)){

		//printf("test : %i\n", test);
		mpz_mod(mod,n,nb);
		//gmp_printf("Debug tour num %Zd : n = %Zd, nb = %Zd, n mod nb = %Zd\n",nb,n,nb,mod);

		if(mpz_cmp_si(mod,0)== 0){
			//printf("Debug : Sortie\n");
			test = 0;
			sortie = 1;
		}
	}


	mpz_clear(nb);
	mpz_clear(max);
	mpz_clear(mod);
	//printf("test : %i\n", test);
	return test;

}
开发者ID:hippunk,项目名称:Etudes,代码行数:43,代码来源:naif.c

示例9: perform_rsa

/*
 * \brief                Encrypts/decrypts a message using the RSA algorithm.
 *
 * \param result         a field to populate with the result of your RSA calculation.
 * \param message        the message to perform RSA on. (probably a cert in this case)
 * \param e              the encryption key from the key_file passed in through the
 *                       command-line arguments
 * \param n              the modulus for RSA from the modulus_file passed in through
 *                       the command-line arguments
 *
 * Fill in this function with your proj0 solution or see staff solutions.
 */
static void
perform_rsa(mpz_t result, mpz_t message, mpz_t e, mpz_t n)
{
  int odd_num;

  mpz_set_str(result, "1", 10);
  odd_num = mpz_odd_p(e);
  while (mpz_cmp_ui(e, 0) > 0) {
    if (odd_num) {
      mpz_mul(result, result, message);
      mpz_mod(result, result, n);
      mpz_sub_ui(e, e, 1);
    }
    mpz_mul(message, message, message);
    mpz_mod(message, message, n);
    mpz_div_ui(e, e, 2);
    odd_num = mpz_odd_p(e);
  }
}
开发者ID:bchanthyra,项目名称:TSL,代码行数:31,代码来源:client.c

示例10: main

int main (int argc, char const *argv[])
{
    mpz_t n;
    mpz_init( n );

#if 0
    /* set up 7th Fermat number */
    mpz_ui_pow_ui( n, 2, 128 );
    mpz_add_ui( n, n, 1);
#else
    /*mpz_set_ui( n, 3248523672894567297 );*/
    mpz_set_str( n, "3248523672894567297", 10 );
#endif

    /* try to factor it */
    fast_fermat_alg( n );

    return 0;
}
开发者ID:danodonovan,项目名称:NumberTheoryInPython,代码行数:19,代码来源:number_theory.c

示例11: while

/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  convertToCryptInt
 *  Description:  
 * =====================================================================================
 */
mpz_t *convertToCryptInt(char *str, int str_size, int *ret_size) {
    mpz_t *result;

    int count = 0, i = 0, j = 0;
    char *tmp = 0;

    while (str[i] != '\0') {
        if (str[i] == ' ')
            count ++;
        i++;
    }

    if (str[strlen(str) - 1] != ' ')
        count ++;

    result = (mpz_t *) malloc (sizeof(mpz_t) * count);

    i = 0;

    while (str[i] != '\0') {
        int nsize = 32, csize = 1;
        tmp = (char *) malloc (sizeof(char) * nsize);
        while(str[i] != ' ' && str[i] != '\0') {
            if (csize == nsize) {
                nsize = nsize << 2;
                tmp = (char *) realloc (tmp, nsize * sizeof(char));
            }
            tmp[csize - 1] = str[i];
            csize ++; i ++;
        }
        tmp[csize - 1] = '\0';
        i ++; 
        mpz_init(result[j]);
        mpz_set_str(result[j], tmp, 10);
        j++;

        free(tmp);
    }

    *ret_size = j;
    return result;
} /* -----  end of function convertToCryptInt  ----- */
开发者ID:MFreeze,项目名称:m2moca,代码行数:48,代码来源:crypt.c

示例12: io_read

istream &
//operator>> (istream &i, mpz_ptr z)
io_read (istream &i, mpz_ptr z)
{
  int base;
  char c = 0;
  string s;
  bool ok = false, zero, showbase;

  i.get(c); // start reading

  if (i.flags() & ios::skipws) // skip initial whitespace
    while (isspace(c) && i.get(c))
      ;

  if (c == '-' || c == '+') // sign
    {
      if (c == '-') // mpz_set_str doesn't accept '+'
	s = "-";
      i.get(c);
    }

  while (isspace(c) && i.get(c)) // skip whitespace
    ;

  base = __gmp_istream_set_base(i, c, zero, showbase); // select the base
  __gmp_istream_set_digits(s, i, c, ok, base);         // read the number

  if (i.good()) // last character read was non-numeric
    i.putback(c);
  else if (i.eof() && (ok || zero)) // stopped just before eof
    i.clear();

  if (ok)
    mpz_set_str(z, s.c_str(), base); // extract the number
  else if (zero)
    mpz_set_ui(z, 0);
  else
    i.setstate(ios::failbit); // read failed

  return i;
}
开发者ID:swarbhanu,项目名称:CGAL-Mesh,代码行数:42,代码来源:GmpIO.cpp

示例13: djcs_import_public_key

int djcs_import_public_key(djcs_public_key *pk, const char *json)
{
    JSON_Value *root = json_parse_string(json);
    JSON_Object *obj = json_value_get_object(root);
    pk->s = json_object_get_number(obj, "s");
    pk->n = malloc(sizeof(mpz_t) * (pk->s + 1));

    mpz_init(pk->n[0]);
    mpz_set_str(pk->n[0], json_object_get_string(obj, "n"), HCS_INTERNAL_BASE);
    json_value_free(root);

    /* Calculate remaining values */
    mpz_add_ui(pk->g, pk->n[0], 1);
    for (unsigned long i = 1; i <= pk->s; ++i) {
        mpz_init_set(pk->n[i], pk->n[i-1]);
        mpz_mul(pk->n[i], pk->n[i], pk->n[0]);
    }

    return 0;
}
开发者ID:tiehuis,项目名称:libhcs,代码行数:20,代码来源:djcs.c

示例14: mpi_mpz_recv

int mpi_mpz_recv(mpz_t z, int src, int tag, MPI_Comm comm, MPI_Status *status) {
    int buf_size;
    int rc = 0;
    void *buf;

    MPI_Recv(&buf_size, 1, MPI_INT, src, tag, comm, status);

    buf = (void *)malloc(sizeof(unsigned char) * buf_size);
    MPI_Recv(buf, buf_size, MPI_BYTE, src, tag, comm, status);

    rc = mpz_set_str(z, buf, 10);
    if (rc) {
        fprintf(stderr, "mpi_mpz_bcast:  mpz_set_str(%s) failed.\n",
            (char*)buf);
        return 0;
    }
 
    recv_cnt++;
    return 1;
}
开发者ID:jsbronder,项目名称:p_aks,代码行数:20,代码来源:gmp_mpi.c

示例15: MKBIGC

VAL MKBIGC(VM* vm, char* val) {
    if (*val == '\0') {
        return MKBIGI(0);
    }
    else {
        idris_requireAlloc(IDRIS_MAXGMP);
        mpz_t* bigint;
        
        VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
        idris_doneAlloc();
        bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
        
        mpz_init(*bigint);
        mpz_set_str(*bigint, val, 10);

        SETTY(cl, CT_BIGINT);
        cl -> info.ptr = (void*)bigint;

        return cl;
    }
}
开发者ID:adamsmd,项目名称:Idris-dev,代码行数:21,代码来源:idris_gmp.c


注:本文中的mpz_set_str函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。