biginteger

How do I implement BN_num_bytes() (and BN_num_bits() ) in C#?

早过忘川 提交于 2019-12-08 15:55:30
问题 I'm porting this line from C++ to C#, and I'm not an experienced C++ programmer: unsigned int nSize = BN_num_bytes(this); In .NET I'm using System.Numerics.BigInteger BigInteger num = originalBigNumber; byte[] numAsBytes = num.ToByteArray(); uint compactBitsRepresentation = 0; uint size2 = (uint)numAsBytes.Length; I think there is a fundamental difference in how they operate internally, since the sources' unit tests' results don't match if the BigInt equals: 0 Any negative number 0x00123456 I

Divide two large numbers as strings without using Bignumbers in java

旧街凉风 提交于 2019-12-08 08:13:10
问题 I need to divide two large integers WITHOUT using Biginteger since the Numbers can't be stored inside a primitive type , since I need to do it char by char from the strings I am given,I have already created a class called BigNumber, with this class I can: Add multiply compare two strings with large integers inside Now I only need to implement the Dividing method but I can't get my head around how to do it with two strings instead of one String and an Int, here's what I got so far, it works if

Parallel.For with BigInteger calculations output different than For loop

蹲街弑〆低调 提交于 2019-12-07 17:47:44
问题 I have the following loop that runs a conversion from base95 to base10. I'm working with several thousand digit numbers, so BigIntegers are required. inst is the base95 string. Parallel.For(0, inst.Length, x => { result += BigInteger.Pow(95, x) * (inst[x] - 32); }); If I work with base95 strings of about 200 characters or less, it works perfectly fine and outputs the same result that a normal for loop would. However, once I start increasing the size of the base95 string, the parallel's output

Integers of unlimited size?

丶灬走出姿态 提交于 2019-12-07 16:39:10
问题 In Python, I can write a program to calculate integers of unlimited size. Just the other day I did the one millionth fibonacci number, and it was so large It was unable to fit in the console. If this is possible to do in Python, which to my understanding was written in C, how could one do the same in C++? It has to be possible, otherwise I don't see how it could be done in Python. I also believe there is something similar in Java/C# called a Biginteger, but I couldn't find anything saying how

Convert arbitrary size of byte[] to BigInteger[] and then safely convert back to exactly the same byte[], any clues?

对着背影说爱祢 提交于 2019-12-07 08:15:09
问题 I believe conversion exactly to BigInteger[] would be optimal in my case. Anyone had done or found this written in Java and willing to share? So imagine I have arbitrary size byte[] = {0xff,0x3e,0x12,0x45,0x1d,0x11,0x2a,0x80,0x81,0x45,0x1d,0x11,0x2a,0x80,0x81} How do I convert it to array of BigInteger's and then be able to recover it back the original byte array safely? ty in advance. 回答1: Use BigInteger.toByteArray() and BigInteger(byte[]). According to the javadoc, the latter ...

Sum a list of BigIntegers

那年仲夏 提交于 2019-12-06 17:19:52
问题 I've looked all over but can't figure this out. How do you sum a list of BigIntegers? Using System.Numerics; Using System.Linq; List<BigInteger> bigInts = new List<BigInteger>(); BigInteger sum = bigInts.Sum(); // doesn't work BigInteger sum = bigInts.Sum<BigInteger>(); // doesn't work BigInteger sum = bigInts.Sum(x => x); // doesn't work Do you have to do this? BigInteger sum = new BigInteger(0); foreach(BigInteger bigint in bigInts) sum += bigint; 回答1: Aggregate function is more general

Divide two large numbers as strings without using Bignumbers in java

删除回忆录丶 提交于 2019-12-06 15:36:40
I need to divide two large integers WITHOUT using Biginteger since the Numbers can't be stored inside a primitive type , since I need to do it char by char from the strings I am given,I have already created a class called BigNumber, with this class I can: Add multiply compare two strings with large integers inside Now I only need to implement the Dividing method but I can't get my head around how to do it with two strings instead of one String and an Int, here's what I got so far, it works if the number we are dividing the String by is small enough to be an int class BigNumber { String Number;

big integers in c++

我怕爱的太早我们不能终老 提交于 2019-12-06 14:27:54
问题 I know this question has probably been asked in this forum many times and in the web as well. I am asked to create an implementation of a big integer in c++, however there is a constraint that one of my constructor should take an int as an argument... so I am guessing there will be more than one non-default constructor... so my question is, what would be the easiest way to do this?? 回答1: The question, then, seems to be "how do I turn an integer into a list of bits"? Put another way, what's

BigIntegers, gcd , modulus inverse to find public key

≡放荡痞女 提交于 2019-12-06 13:42:46
So, Im using java to find the public key of a RSA password. Right now Im unsure what I'm doing and also if it's correct. I have this information for the public key. C = 5449089907 n = p*q = 8271344041 q = 181123 p = n/q = 45667 d = 53 phi(n) = (p-1)(q-1) = 8271117252 What complicates things are the BigIntegers, the numbers are way to huge for int and longs, so I have to use the clumsy BigIntegers. As far as I understand I have the following equation to solve. e*5198987987 - x*8271117252 = 1 I'm trying to use euklidske algorithm to solve it. In Java i think i can use the following method : I

BigInteger numbers implementation and performance

笑着哭i 提交于 2019-12-06 12:47:48
问题 I have written a BigInteger class in C++ that should be able to do operations on all numbers with any size. Currently I am trying to achieve a very fast multiplication method by comparing the existing algorithms and test for which amount of digits they work best and I ran into very unexpected results.I tried to do 20 multiplications of 500-digit and I timed them. This was the result: karatsuba: 14.178 seconds long multiplication: 0.879 seconds Wikipedia told me It follows that, for