Click here to Skip to main content
14,428,864 members
Rate this:
Please Sign up or sign in to vote.
See more:
Wrong output for 141 mod 8 ??
I am just trying to read an input from file and then apply mod
with 8.Can u please explain me where I am getting wrong ?

What I have tried:

#include<stdio.h>
#include<openssl/bn.h>

BIGNUM * read_f(const char *filename)
{
    FILE *fp;
    char text[700];
    fp=fopen(filename,"r");
    fgets(text,700,fp);
    //fclose(fp);
    //char *point=text;
    BIGNUM*a =BN_new();
    BN_hex2bn(&a, (const char *) text);
    fclose(fp);
    return a;
}
void main(){
 const char *filename="input/tA.txt";
    BIGNUM *p=  BN_new();
    p=read_f(filename);
    BN_print_fp(stdout,p);
    printf("\n");
	BIGNUM *tmp=BN_new();
	BIGNUM *val=BN_new();
	BN_set_word(val,8);
      
	//BIGNUM *v=BN_new();
	//BN_set_word(v,1);
 	BN_CTX *ctx=BN_CTX_new();
        //calculating mod value
  	BN_mod(tmp,p,val,ctx);	
	BN_print_fp(stdout,tmp);
	printf("\n");
 	//calculati
 	// BN_mod_mul(tmp,p,v,val,ctx);
	//BN_print_fp(stdout,tmp);
	//printf("\n");
}
Posted
Updated 13-Jun-17 0:14am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

It works fine, of course, try:
#include <openssl/bn.h>
int main()
{
  BIGNUM *b1=BN_new();
  BIGNUM *b2=BN_new();
  BIGNUM *b3=BN_new();
  BN_set_word(b1,141);
  BN_set_word(b2,8);
  BN_CTX *ctx=BN_CTX_new();

  BN_mod(b3,b1,b2,ctx);
  BN_print_fp(stdout,b3);

  BN_free(b1);
  BN_free(b2);
  BN_free(b3);
  BN_CTX_free(ctx);

  return 0;
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100