bignum

custom data type in C

流过昼夜 提交于 2020-01-01 05:19:08
问题 I am working with cryptography and need to use some really large numbers. I am also using the new Intel instruction for carryless multiplication that requires m128i data type which is done by loading it with a function that takes in floating point data as its arguments. I need to store 2^1223 integer and then square it and store that value as well. I know I can use the GMP library but I think it would be faster to create two data types that both store values like 2^1224 and 2^2448. It will

SHA256 Hash results different across Android & iOS for Big numbers

时光怂恿深爱的人放手 提交于 2019-12-31 22:39:35
问题 I'm trying to Hash a BigInteger/BigNum and I'm getting different results in Android/iOS. I need to get the same Hash result so that both the apps work as per the SRP protocol. On closer inspection it is working fine for positive numbers but not working for negative numbers (first nibble greater than 7). Not sure which one is correct and which one is to be adjusted to match with the other. Android: void hashBigInteger(String s) { try { BigInteger a = new BigInteger(s, 16); MessageDigest sha =

RangeError: bignum too big to convert into `long'

人走茶凉 提交于 2019-12-23 00:46:12
问题 num = "0000001000000000011000000000000010010011000011110000000000000000" for n in 0...num.length temp = num[n] dec = dec + temp*(2**(num.length - n - 1)) end puts dec When i am running this code in irb the following error message is the output. and when i compiled the same logic in python it is working absolutely fine. I have Googled "RangeError: bignum too big to convert into `long': but didn't find the relevant answer. Please help me :( Thanks in Advance. RangeError: bignum too big to

How can I compute double factorials in Perl?

拟墨画扇 提交于 2019-12-22 20:43:49
问题 Given Wikipedia's discussion of Double Factorials, can anyone suggest where I might find a bignum version of this for Perl, or else suggest how it might be written? 回答1: Perl will handle whatever your C compiler can handle, for anything bigger you should be using Math::BigInt. I would recommend you read perlnumber. A definition for the double factorial (in perl golf): sub f{$_[0]&&$_[0]>=2?$_[0]*f($_[0]-2):1} 回答2: Here are lots of alternative approaches to implementing Fast Factorial

Recursive function calculating factorials leads to stack overflow

▼魔方 西西 提交于 2019-12-22 03:50:31
问题 I tried a recursive factorial algorithm in Rust. I use this version of the compiler: rustc 1.12.0 (3191fbae9 2016-09-23) cargo 0.13.0-nightly (109cb7c 2016-08-19) Code: extern crate num_bigint; extern crate num_traits; use num_bigint::{BigUint, ToBigUint}; use num_traits::One; fn factorial(num: u64) -> BigUint { let current: BigUint = num.to_biguint().unwrap(); if num <= 1 { return One::one(); } return current * factorial(num - 1); } fn main() { let num: u64 = 100000; println!("Factorial {}!

Will Erlang have Bignums for math functions?

不想你离开。 提交于 2019-12-20 06:18:56
问题 Why does Erlang not include arbitrary precision for math functions? I recently had to use math:pow(2,4333) , and it throws an error. Why does Erlang not use libraries like GMP? Are there any plans to include it in the standard library? (Haskell uses it, [strike]even Java has bignums[strike]). Thanks. Update: To add more perspective, I understand that it can be done using NIFs. I was solving problems from hackerrank in which the input uses larger numbers. pow/2 can be easily written in Erlang

Bignum division with an unsigned 8 bit integer. C

坚强是说给别人听的谎言 提交于 2019-12-13 04:28:44
问题 I've created an algorithm for dividing a integer up to 255 bytes in size by an 8 bit integer and it works with the tests I've done. Does anyone have any comments for it or any improvement suggestions? Is there a better algorithm for this purpose? I don't want a bignum by bignum division algorithm, the second integer is an 8 bit integer. Best solution so far (small endian): typedef struct{ u_int8_t * data; u_int8_t length; }CBBigInt; void CBBigIntEqualsDivisionByUInt8(CBBigInt * a,u_int8_t b,u

How to serialize the GMP mpf type?

血红的双手。 提交于 2019-12-12 07:58:01
问题 It seems that GMP provides only string serialization of the mpf (floating point) type: mpf_get_str() , mpf_class::get_str() The mpz (integer) type has an additional interface for raw bytes: mpz_out_raw() http://gmplib.org/manual/Function-Index.html Am I missing something? Does anyone know of another library that can serialize GMP floats? Does anyone know of another bignum lib that offers robust serialization? Edit: I'd be happy with serializing MPFR's mpfr_t, as well, which similarly only