biginteger

BigInteger.Parse() on hexadecimal number gives negative numbers

為{幸葍}努か 提交于 2019-12-10 14:22:44
问题 I've started using .NET 4 System.Numerics.BigInteger Structure and I've encountered a problem. I'm trying to parse a string that contains a hexadecimal number with no sign (positive). I'm getting a negative number. For example, I do the following two asserts: Assert.IsTrue(System.Int64.Parse("8", NumberStyles.HexNumber, CultureInfo.InvariantCulture) > 0, "Int64"); Assert.IsTrue(System.Numerics.BigInteger.Parse("8", NumberStyles.HexNumber, CultureInfo.InvariantCulture) > 0, "BigInteger"); The

Square Root for Bigint in F#

妖精的绣舞 提交于 2019-12-10 14:19:39
问题 Is there a way to get the square root of a big integer? I am dealing with numbers that are much too large for int64 to handle so bigint is a must. I was considering the idea of implementing it myself using the Babylonian method, but want to know if there are any built in functions for this first. Thanks in advance. 回答1: You can use newton's method on any scalar. http://en.wikipedia.org/wiki/Newton%27s_method -- MarkusQ P.S. See also http://en.wikipedia.org/wiki/Methods_of_computing_square

Best way to sum concurrently

蹲街弑〆低调 提交于 2019-12-10 13:32:03
问题 I am trying to compute some big numbers. In order to speed up computation, I would like to make use of multithreading. Each thread should calculate a number and in the end a sum is calculated. I once saw something that worked with a SumThread and a Collector that looked as follows: public BigInteger compute(int p) { Collector c = new Collector(p); for(T element : Collection<T> bigCollection) { new SumThread(c) { @Override protected void doTheJob() { long big = someVeryComplexCalculation

Converting BigInteger to binary string

半腔热情 提交于 2019-12-10 12:28:47
问题 Can we convert Biginteger to binary string String s1 = "0011111111101111111111111100101101111100110000001011111000010100"; String s2 = "0011111111100000110011001100110011001100110011001100110011001100"; BigInteger bi1, bi2, bi3; bi1 = new BigInteger(s1,2); bi2 = new BigInteger(s2,2); bi3 = bi1.xor(bi2); How to convert bi3 to binary string 回答1: You can use toString(radix) for that: String s3 = bi3.toString(2); 回答2: import java.math.BigInteger; import java.util.Scanner; public static void main

MillerRabin primality test in C#

久未见 提交于 2019-12-10 10:54:42
问题 Welcome. I am trying to implement MillerRabin test for checking if large given number is a prime. Here is my code: public static bool MillerRabinTest(BigInteger number) { BigInteger d; var n = number - 1; var s = FindK(n, out d); BigInteger a = 2; BigInteger y = Calc(a, d, number); //a^d mod number if (y != BigInteger.One && y != n) { for (var r = 1; r <= s - 1; r++) { y = Calc(y, 2, number); if (y == 1) return false; } if (y != n) return false; } return true; //it is probably prime } It is

bigint truncated via PDO?

大憨熊 提交于 2019-12-10 03:31:26
问题 I came across a problem with storing a large integer in a BIGINT column on MySQL via PDO If i run this test: $number = "30123456789"; var_dump($number); //prints string(11) "30123456789" $new_number = (int)$number; var_dump($new_number); //prints int(30123456789) So far so good... If I run this SQL directly in MySQL: update my_table set bigint_field = 30123456789 where id_field = 1 Everything works fine... The problem arise when I try to save that number via PDO and I reduced the problem to

How to pass BigInteger to a Signature function

这一生的挚爱 提交于 2019-12-10 00:30:55
问题 Here I'm implementing digital signature using RSA. I read a plain text from a file and get MD5 i.e instance of a MessageDigest of the plain text and converting that plain text to BigInteger here this bigInteger should be signed. MessageDigest m1 = MessageDigest.getInstance("MD5"); m1.update(bFile); byte [] digest1 = m1.digest(); for(int i=0; i < digest1.length ; i++){ System.out.println("b["+i+"]="+digest1[i]); } BigInteger bi = new BigInteger(digest1); //here I dont know how to pass

BigInteger addition always 0

旧时模样 提交于 2019-12-08 19:46:35
问题 I have the following issue: when trying to add to a sum of BigIntegers the outcome remains 0. Here is the code: public void NumberOfOutcomes(int x, int y){ BigInteger first = BigInteger.valueOf(0); BigInteger second = BigInteger.valueOf(0); for(int i = 0; i <= (x / 2); i++){ first.add( fac(x - i).divide((fac(x - 2*i).multiply(fac(i)))) ); System.out.println("First " + first.add( fac(x - i).divide((fac(x - 2*i).multiply(fac(i)))) )); } for(int i = 0; i <= (y / 2); i++){ second.add( fac(y - i)

Is bigint large enough for an event log table?

不打扰是莪最后的温柔 提交于 2019-12-08 19:28:47
问题 Now I know that bigint is 2^64; that is, more atoms than there are in the known universe. I shouldn't be worried, as my mere human brain simply can't get around the enormity of that number. However, let's say that I record every change to every category, product and order in my system, from launch until the end of time. Should I be concerned about the performance of table writes before I worry about running out of primary key values? Should I record events of different priorities to different

Securely generating a uniformly random BigInteger

谁说胖子不能爱 提交于 2019-12-08 18:20:48
问题 I want to securely generate a random number in the range [0, N), where N is a parameter. However, System.Security.Cryptography.RandomNumberGenerator only provides a GetBytes() method to fill an array with random values. (I need the random integers for nonces used in a slightly modified version of SRP. The "slightly modified" part is out of my control, and the only reason I'm even touching crypto stuff.) I have written a method to do this, but I'm looking for a better way or at least