Пример #1
0
unsigned int step1( unsigned char* buffer, int buflen )
{
    // self.x2 = createRandomExponent()
    // self.x3 = createRandomExponent()
    x2 = createRandomExponent();
    x3 = createRandomExponent();

    // g2 = pow( gen, x2, mod)  // genx^x2 % mod
    g2 = my_pow( gen, x2, mod );
    
    // g3 = pow( gen, x3, mod )
    g3 = my_pow( gen, x3, mod );
    
    // (c1, d1) = self.createLogProof(1, self.x2)
    createLogProof( "1", x2, c1, d1 );
    // (c2, d2) = self.createLogProof(2, self.x3)
    createLogProof( "2", x3, c2, d2 );

    /*
     # Send g2a, g3a, c1, d1, c2, d2
     return packList(self.g2, self.g3, c1, d1, c2, d2)
     */
    memset( buffer, 0x00, buflen );
    unsigned char* next = simplePack( buffer, g2 );
    next = simplePack( next, g3 );
    next = simplePack( next, c1 );
    next = simplePack( next, d1 );
    next = simplePack( next, c2 );
    next = simplePack( next, d2 );
    
    return ( unsigned int )( next - buffer );
}
Пример #2
0
int		my_put_nbr(int nb)
{
  unsigned char	len;
  int		copy;
  int		diz;

  if (nb == -2147483648)
    {
      cheat();
      return (0);
    }
  nb = is_negative(nb);
  copy = nb;
  len = 1;
  while (copy > 9)
    {
      copy = copy / 10;
      len = len + 1;
    }
  while (len != 0)
    {
      diz = nb / my_pow(len-1);
      my_putchar(diz + 48);
      nb = nb - diz * my_pow(len-1);
      len = len - 1;
    }
}
Пример #3
0
//文字列を実数に変換
double my_atof(char* string)
{
	double ret = 0;
	int int_length = 0;
	int float_length = 0;
	int i;

	for(i=0;string[i]!='\0';i++);

	//整数部の文字数を取得
	for(int_length=0;string[int_length]!='\0';)
	{
		if(string[int_length]>='0'&&string[int_length]<='9')
		{
			int_length++;
		}
		else
		{
			break;
		}
	}

	//小数部のスタートを求める
	if(string[int_length]=='.')
	{
		float_length = i - int_length - 1;
	}

	#ifdef _Debug_enable
		//デバッグ用
		printf("\t\tDebug : my_atof -> i = %d,int_length = %d,float_length = %d\n",i,int_length,float_length);
	#endif

	//整数部の処理
	for(i=0;i<int_length;i++)
	{
		ret += (string[i] - '0') * my_pow(10,int_length-i-1);
		#ifdef _Debug_enable
			//デバッグ用
			printf("\t\tDebug : my_atof -> ret = %lf\n",ret);
		#endif
	}

	//小数部の処理
	for(i=0;i<float_length;i++)
	{
		ret += (string[int_length+i+1] - '0') * my_pow(10,-i-1);
		#ifdef _Debug_enable
			//デバッグ用
			printf("\t\tDebug : my_atof -> ret = %lf\n",ret);
		#endif
	}

	#ifdef _Debug_enable
		//デバッグ用
		printf("\t\tDebug : my_atof -> \"%s\" to %lf\n",string,ret);
	#endif

	return ret;
}
Пример #4
0
unsigned long long my_pow (unsigned long long n, unsigned long long p){
	if (0 == p)
		return 1;
	else if (p % 2 == 0)
		return my_pow(mult_last_10_dig(n, n), p/2);
	else
		return mult_last_10_dig(n, my_pow(n, p-1));
}
Пример #5
0
unsigned long my_pow(int x, int n) 
{
	if (n == 1) 
		return x;
	else if (n % 2 == 0)
		return my_pow(x, n/2) * my_pow(x, n/2);
	else 
		return (my_pow(x, n/2) * my_pow(x, n/2) * x);
}
float round_n(float val,int n){
	float result=0;
	float temp=0;

	temp =(int)(val*my_pow(10,n));
	result=(float)temp/my_pow(10,n);
	
	return result;

}
Пример #7
0
// def createCoordsProof(self, version, g2, g3, r):
void createCoordsProof( char* version, BIGNUM* g2, BIGNUM* g3, BIGNUM* r, BIGNUM* c, BIGNUM* d1, BIGNUM* d2 )
{
    // r1 = createRandomExponent()
    // r2 = createRandomExponent()
    BIGNUM* r1 = createRandomExponent();
    BIGNUM* r2 = createRandomExponent();
    
    // tmp1 = pow(g3, r1, self.mod)
    BIGNUM* tmp1 = my_pow( g3, r1, mod );
    
    // tmp2 = mulm( pow(self.gen, r1, self.mod), pow(g2, r2, self.mod), self.mod)
    // Step A = pow(self.gen, r1, self.mod)
    BIGNUM* stepA = my_pow( gen, r1, mod );
    
    // Step B = pow(g2, r2, self.mod)
    BIGNUM* stepB = my_pow( g2, r2, mod );
    
    // Step C = mulm( StepA, StepB, mod )
    BIGNUM* tmp2 = mulm( stepA, stepB, mod );
    
    // c = sha256(version + str(tmp1) + str(tmp2))
    BIGNUM* tmp3 = sha_with_version( version, tmp1, tmp2 );
    BN_copy( c, tmp3 );
    
    // d1 = (r1 - mulm(r, c, self.modOrder)) % self.modOrder
    BIGNUM* resultA = mulm( r, c, modOrder );
    BIGNUM* d1_temp = subm( r1, resultA, modOrder );
    BN_copy( d1, d1_temp );
    
    // d2 = (r2 - mulm(self.secret, c, self.modOrder)) % self.modOrder
    BIGNUM* resultB = mulm( secret, c, modOrder );
    BIGNUM* d2_temp = subm( r2, resultB, modOrder );
    BN_copy( d2, d2_temp );

    // clean up
    BN_clear_free( r1 );
    BN_clear_free( r2 );
    BN_clear_free( tmp1 );
    BN_clear_free( stepA );
    BN_clear_free( stepB );
    BN_clear_free( tmp2 );
    BN_clear_free( tmp3 );
    BN_clear_free( resultA );
    BN_clear_free( d1_temp );
    BN_clear_free( resultB );
    BN_clear_free( d2_temp );
    
    // return (c, d1, d2)
}
Пример #8
0
static void tet_test(void)
{
  mesh* m;
  point pts[4];
  ment v[4];
  ment e;
  unsigned i;
  double V;
  double A[4];
  double s;
  m = mesh_new();
  pts[0] = point_new(-1, 0, -1.0 / my_sqrt(2));
  pts[1] = point_new( 1, 0, -1.0 / my_sqrt(2));
  pts[2] = point_new( 0,-1,  1.0 / my_sqrt(2));
  pts[3] = point_new( 0, 1,  1.0 / my_sqrt(2));
  for (i = 0; i < 4; ++i)
    v[i] = ment_new(m, VERTEX, 0);
  for (i = 0; i < 4; ++i)
    mesh_set_point(m, v[i], pts[i]);
  e = ment_new(m, TET, v);
  V = tet_volume(ment_tet(m, e));
  debug("volume: %e\n", V);
  s = 0;
  for (i = 0; i < 4; ++i) {
    mesh_down(m, e, TRIANGLE, i, v);
    A[i] = triangle_area(verts_triangle(m, v));
    debug("area: %e\n", A[i]);
    s += A[i] * A[i];
  }
  s /= 4;
  s = my_pow(s, 3.0 / 4.0);
  debug("condition bound: %.10e\n", V / s);
  debug("quality: %e\n", ment_quality(m, e));
  mesh_free(m);
}
Пример #9
0
float my_pow(float a, float b)
{
	float res = 0.0;
	if (b < 0)
	{
		res = my_pow(a, (b + 1))*(1/a);
		return res;
	}
	if (b == 0)
		return 1.0;
	if (b > 0)
	{
		res = a*my_pow(a, b - 1);
		return res;
	}
}
Пример #10
0
int	my_getnbr(char *str)
{
  int	i;
  int	pos;
  int	len;
  int	sign;

  sign = 0;
  i = 0;
  while ((str[i] < '0' || str[i] > '9') && str[i] != '\0')
    {
      if (str[i] == '-')
	sign = sign + 1;
      i = i + 1;
    }
  pos = i;
  if (sign % 2 == 1)
    sign = -1;
  else
    sign = 1;
  while (str[i] >= '0' && str[i] <= '9')
    i++;
  len = i - pos;
  return (my_pow(pos, len, str, sign));
}
Пример #11
0
int main(void){
	unsigned long long p = (28433 * my_pow(2, 7830457) + 1) % 10000000000;

	printf("%lld\n", p);

	return 0;
}
Пример #12
0
void    int_to_hexa_add(int nb, char *dest, int a)
{
  int   r;
  int   i;
  int   c;

  c = 0;
  i = 7;
  while (i != -2)
    {
      r = my_pow(16, i);
      if (nb - r >= 0)
        {
          nb = nb - r;
          c++;
        }
      else
        {
          i--;
          dest[a] = hexa_in_str_add(c, dest, a);
          c = 0;
          a++;
        }
    }
}
Пример #13
0
char	*convert_bin(int nb, int i)
{
  char	*str;
  int	a;
  int	r;

  a = 0;
  if ((str = malloc(sizeof(i))) == NULL)
    my_exit("MALLOC FAILED\n");
  while (i != -1)
    {
      r = my_pow(2, i);
      if (nb - r >= 0)
        {
          str[a] = '1';
          nb = nb - r;
        }
      else
        str[a] = '0';
      a++;
      i--;
    }
  str[a] = '\0';
  return (str);
}
void float_to_string(float float_val,char *string){
int seisu_len=0;
int int_val=0;
int divisor =0;
int i;

seisu_len = get_int_digit((int)float_val);
int_val = (float_val*100);
divisor = my_pow(10,seisu_len+1);
	
	
if (int_val >= 0)
string[0] = ' ';
else {
string[0] = '-';
int_val *= -1;
}

for(i=1;i<=seisu_len+3;++i){
	if(i==seisu_len+1){
		string[i]='.';
	}
	else {
	string[i] = (unsigned char)(int_val / divisor) + '0';
	int_val %= divisor;
	divisor /=10;
	}
}
string[i] = '\0';


}
Пример #15
0
static int	my_pow(int nb, int power)
{
  if (power == 0)
    return (1);
  else if (power > 1)
    nb = nb * my_pow(nb, power - 1);
  return (nb);
}
unsigned long sum_digit_powers(unsigned long n, unsigned p) {
	unsigned long s = 0;
	while (n > 0) {
		s += my_pow(n % 10, p);
		n /= 10;
	}
	return s;
}
Пример #17
0
// def checkCoordsProof(self, version, c, d1, d2, g2, g3, p, q):
int checkCoordsProof( char* version, BIGNUM* c, BIGNUM* d1, BIGNUM* d2, BIGNUM* g2, BIGNUM* g3, BIGNUM* p, BIGNUM* q )
{
    // tmp1 = mulm(pow(g3, d1, self.mod), pow(p, c, self.mod), self.mod)
    // Step A = pow(g3, d1, self.mod)
    BIGNUM* stepA = my_pow( g3, d1, mod );
    
    // Step B = pow(p, c, self.mod)
    BIGNUM* stepB = my_pow( p, c, mod );
    
    // Step C = mulm( StepA, StepB, mod )
    BIGNUM* tmp1 = mulm( stepA, stepB, mod );
    
    // tmp2 = mulm(mulm(pow(self.gen, d1, self.mod), pow(g2, d2, self.mod), self.mod), pow(q, c, self.mod), self.mod)
    // Step A = pow(self.gen, d1, self.mod)
    stepA = my_pow( gen, d1, mod );
    
    // Step B = pow(g2, d2, self.mod)
    stepB = my_pow( g2, d2, mod );
    
    // Step C = pow(q, c, self.mod)
    BIGNUM* stepC = my_pow( q, c, mod );
    
    // Step D = mulm( StepA, StepB, self.mod )
    BIGNUM* stepD = mulm( stepA, stepB, mod );
    
    // Step E = mulm( StepD, StepC, mod )
    BIGNUM* tmp2 = mulm( stepD, stepC, mod );
    
    // cprime = sha256(version + str(tmp1) + str(tmp2))
    BIGNUM* cprime = sha_with_version( version, tmp1, tmp2 );
    int ret = BN_cmp( c, cprime );
    
    // clean up
    BN_clear_free( stepA );
    BN_clear_free( stepB );
    BN_clear_free( tmp1 );
    BN_clear_free( tmp2 );
    BN_clear_free( stepC );
    BN_clear_free( stepD );
    BN_clear_free( cprime );
    
    // return (c == cprime)
    return ( ret == 0 );
}
Пример #18
0
void simple_3d_trans(_xyz_f_t *ref, _xyz_f_t *in, _xyz_f_t *out) //С·¶Î§ÄÚÕýÈ·¡£
{
	static s8 pn;
	static float h_tmp_x,h_tmp_y;
	
	h_tmp_x = my_sqrt(my_pow(ref->z) + my_pow(ref->y));
	h_tmp_y = my_sqrt(my_pow(ref->z) + my_pow(ref->x));
	
	pn = ref->z < 0? -1 : 1;
	
	  out->x = ( h_tmp_x *in->x - pn *ref->x *in->z ) ;
		out->y = ( pn *h_tmp_y *in->y - ref->y *in->z ) ;
	
// 	 out->x = h_tmp_x *in->x - ref->x *in->z;
// 	 out->y = ref->z *in->y - ref->y *in->z;
	
	out->z = ref->x *in->x + ref->y *in->y + ref->z *in->z ;

}
int func(int start, int r){
	int result = 0;
	int start_cpy = start;
	while(start_cpy != 0){
		int tmp = start_cpy % 10;
		start_cpy /= 10;

		result += my_pow(tmp, r);
	}
	return result;
}
Пример #20
0
int	my_pow(int nb, int power)
{
  int	tmp;

  if (power == 0)
    return (1);
  tmp = my_pow(nb, power / 2);
  if (power % 2 == 0)
    return (tmp * tmp);
  else
    return (nb * tmp * tmp);
}
Пример #21
0
double my_pow(double number, int power) {

	double result = 1;
	if(power < 0)
		return my_pow(1/number, -power);
	else
		for(int i = 0; i < power; i++) {
			result *= number;
		}

	return result;
}
Пример #22
0
int main()
{
	float x = 27.0, y = x, y_ = 0.0;
	do
	{
		y_ = y;
		y = 0.5 *(y + (3 * x / (2 * y * y + x / y)));
	} while (my_abs(y - y_) >= my_pow(10, -5));
	std::cout << y << std::endl;
	system("pause");
	return 0;
}
Пример #23
0
int main() {

	double number;
	int power;

	printf("Enter some numbers:" ); // input
	scanf("%lf %d", &number, &power);

	number = my_pow(number, power);

	printf("%lf\n", number); // output

}
Пример #24
0
// def checkEqualLogs(self, version, c, d, g3, qab, r):
int checkEqualLogs( char* version, BIGNUM* c, BIGNUM* d, BIGNUM* g3, BIGNUM* qab, BIGNUM* r )
{
    // tmp1 = mulm(pow(self.gen, d, self.mod), pow(g3, c, self.mod), self.mod)
    // Step A = pow(self.gen, d, self.mod)
    BIGNUM* stepA = my_pow( gen, d, mod );
    
    // Step B = pow(g3, c, self.mod)
    BIGNUM* stepB = my_pow( g3, c, mod );
    
    // Step C = mulm( StepA, StepB, mod )
    BIGNUM* tmp1 = mulm( stepA, stepB, mod );
    BN_clear_free( stepA );
    BN_clear_free( stepB );
    
    // tmp2 = mulm(pow(qab, d, self.mod), pow(r, c, self.mod), self.mod)
    // Step A = pow(qab, d, self.mod)
    stepA = my_pow( qab, d, mod );
    
    // Step B = pow(r, c, self.mod)
    stepB = my_pow( r, c, mod );
    
    // Step C = mulm( StepA, StepB, mod )
    BIGNUM* tmp2 = mulm( stepA, stepB, mod );
    
    // cprime = sha256(version + str(tmp1) + str(tmp2))
    BIGNUM* cprime = sha_with_version( version, tmp1, tmp2 );
    int ret = ( BN_cmp( c, cprime ) == 0 );
    
    // clean up
    BN_clear_free( stepA );
    BN_clear_free( stepB );
    BN_clear_free( tmp1 );
    BN_clear_free( tmp2 );
    BN_clear_free( cprime );
    
    // return (c == cprime)
    return ret;
}
Пример #25
0
// def checkLogProof(self, version, g, c, d):
int checkLogProof( char* version, BIGNUM* g, BIGNUM* c, BIGNUM* d )
{
    // gd = pow( gen, d, mod )
    BIGNUM* gd = my_pow( gen, d, mod );
    
    // gc = pow( g, c, mod)
    BIGNUM* gc = my_pow( g, c, mod );
    
    // gdgc = gd * gc % self.mod
    BIGNUM* gdgc = mulm( gd, gc, mod );
    
    // return (sha256(version + str(gdgc)) == c)
    BIGNUM* bnShaBytes = sha_with_version( version, gdgc, NULL );
    int ret = BN_cmp( bnShaBytes, c );
    
    // clean up
    BN_clear_free( gd );
    BN_clear_free( gc );
    BN_clear_free( gdgc );
    BN_clear_free( bnShaBytes );
    
    return ( ret == 0 );
}
Пример #26
0
static void	write_on_arena(t_arena *arena, int pos, int size, int result)
{
  int		k;
  int		i;

  i = -1;
  k = size - 1;
  while (k >= 0)
    {
      arena->arena[ABS(pos, arena->mem_size)] = (result / my_pow(256, k));
      pos++;
      k--;
    }
}
Пример #27
0
static void test_file_var_subst(char** file, struct np_test_var* vars, int test_no) {
	int value_list_idx;
	char* search_var, *ptr, *file_tmp, *value_range_val;

	for (; vars != NULL; vars = vars->next) {
		asprintf(&search_var, "__%s__", vars->name);
		while ((ptr = strstr(*file, search_var)) != NULL) {
			/* file var found */

			file_tmp = strndup(*file, ptr-(*file));
			ptr += strlen(search_var);
			if (vars->value_list != NULL) {
				value_list_idx = test_no % vars->value_list_count;
				/* realloc to fit string before the variable, the substituted content, the rest of the original string and ending zero */
				file_tmp = realloc(file_tmp, strlen(file_tmp)+strlen(vars->value_list[value_list_idx])+strlen(ptr)+1);
				strcat(file_tmp, vars->value_list[value_list_idx]);
			} else {
				if (vars->value_range_op == ADD) {
					asprintf(&value_range_val, "%d", vars->value_range_start + test_no*vars->value_range_step);
				} else if (vars->value_range_op == SUB) {
					asprintf(&value_range_val, "%d", vars->value_range_start - test_no*vars->value_range_step);
				} else if (vars->value_range_op == MUL) {
					asprintf(&value_range_val, "%d", vars->value_range_start * my_pow(vars->value_range_step, test_no));
				} else if (vars->value_range_op == DIV) {
					asprintf(&value_range_val, "%d", vars->value_range_start / my_pow(vars->value_range_step, test_no));
				}
				file_tmp = realloc(file_tmp, strlen(file_tmp)+strlen(value_range_val)+strlen(ptr)+1);
				strcat(file_tmp, value_range_val);
				free(value_range_val);
			}
			strcat(file_tmp, ptr);
			free(*file);
			*file = file_tmp;
		}
		free(search_var);
	}
}
Пример #28
0
int	my_pow(int a, int b)
{
  int	res;

  res = 1;
  if (b < 0)
  {
    return (-1);
  }
  if (b > 0)
  {
    res = my_mul(a,  my_pow(a, b - 1));
  }
  return (res);
}
Пример #29
0
// def createEqualLogsProof(self, version, qa, qb, x):
void createEqualLogsProof( char* version, BIGNUM* qa, BIGNUM* qb, BIGNUM* x, /* out */BIGNUM* c, /* out */BIGNUM* d )
{
    // r = createRandomExponent()
    BIGNUM* r = createRandomExponent();
    
    // tmp1 = pow(self.gen, r, self.mod)
    BIGNUM* tmp1 = my_pow( gen, r, mod );
    
    // qab = mulm(qa, qb, self.mod)
    BIGNUM* qab = mulm( qa, qb, mod );
    
    // tmp2 = pow(qab, r, self.mod)
    BIGNUM* tmp2 = my_pow( qab, r, mod );
    
    // c = sha256(version + str(tmp1) + str(tmp2))
    BIGNUM* c_temp = sha_with_version( version, tmp1, tmp2 );
    BN_copy( c, c_temp );
    BN_clear_free( tmp1 );
    
    // tmp1 = mulm(x, c, self.modOrder)
    tmp1 = mulm( x, c, modOrder );
    
    // d = (r - tmp1) % self.modOrder
    BIGNUM* d_temp = subm( r, tmp1, modOrder );
    BN_copy( d, d_temp );
    
    // return (c, d)
    
    // clean up
    BN_clear_free( r );
    BN_clear_free( tmp1 );
    BN_clear_free( qab );
    BN_clear_free( tmp2 );
    BN_clear_free( c_temp );
    BN_clear_free( d_temp );
}
Пример #30
0
char	*setnbr(int nbr)
{
    char	*numb;
    int	i;
    int	p;

    p = 10;
    if ((numb = malloc(sizeof(char) * 10)) == NULL)
        return (NULL);
    numb[9] = 0;
    i = 0;
    while (p >= 0)
        numb[p--] = ((nbr / (int)(my_pow(10, i++)) % 10) + '0');
    return (cleanstr(numb));
}