Click here to Skip to main content
15,501,036 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

C++
#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

It works fine, of course, try:
C
#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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900