biginteger

RSA Implementation in C#

北慕城南 提交于 2019-12-06 10:53:22
问题 I am trying to implement the RSA Algorithm in C#. The code below works when p and q are small, but not when trying to replicate RSA-100 or greater where p and q are very large. For example when: p = 61, q = 53, n = 3233, phi(n) = 3120, e = 17, d = 2753 Once decrypted, I get the correct original messsage. I got these values from the RSA Wikipedia page. The code also works for other small values of p and q. However, when using RSA-100 or greater, I do not get back my original message. I have

MillerRabin primality test in C#

我的未来我决定 提交于 2019-12-06 08:47: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 working fine for small Bigintegers. But if my programs needs to evalute numbers containing of more than

128 bit arithmetic on x64 in C

陌路散爱 提交于 2019-12-06 05:06:44
问题 When implementing bignums on x86, obviously the most efficient choice for digit size is 32 bits. However, you need arithmetic up to twice the digit size (i.e. 32+32=33, 32*32=64, 64/32=32). Fortunately, not only does x86 provide this, but it's also accessible from portable C (uint64_t). Similarly, on x64 it would be desirable to use 64-bit digits. This would require 128 bit arithmetic (i.e. 64+64=65, 64*64=128, 128/64=64). Fortunately, x64 provides this. Unfortunately, it's not accessible

Big Integer addition, I know the theory… still rusty in practice

社会主义新天地 提交于 2019-12-06 03:05:19
so, I'm trying to build a simple big integer class, I've read some pages on the internet and all that, but I'm stuck. I know the theory and I know that I need a carry but all examples I've seen, they focuded more in chars and in base 10 and well, I'm using a different approach to make it a bit more faster. I would appreciate some help with the plus assignment operator, the rest of it I'll try to figure it out by myself. #include <iostream> #include <string> #include <vector> using std::cout; using std::endl; class big_integer { using box = std::vector<int unsigned>; box data {0}; box split(std

Why doesn't my processor have built-in BigInt support?

瘦欲@ 提交于 2019-12-05 20:34:38
问题 As far as I understood it, BigInts are usually implemented in most programming languages as arrays containing digits, where, eg.: when adding two of them, each digit is added one after another like we know it from school, e.g.: 246 816 * * ---- 1062 Where * marks that there was an overflow. I learned it this way at school and all BigInt adding functions I've implemented work similar to the example above. So we all know that our processors can only natively manage ints from 0 to 2^32 / 2^64 .

BigInteger to Hexadecimal

只愿长相守 提交于 2019-12-05 18:16:18
问题 Quick question... I have a stupidly long BigInteger which I would like to write to a file as a hex string. I know Java provides the .toString(16) method which does this, but I can't find an equivalent in C#. I'm using System.Numerics.BigInteger from .NET 4.0. Thanks 回答1: Use .ToString("X") or .ToString("x") depending on what case you prefer. 回答2: Can you not use yourBI.ToString("X") ? http://msdn.microsoft.com/en-us/library/dd268260.aspx 来源: https://stackoverflow.com/questions/4988858

Golang Big Integers to Binary String

陌路散爱 提交于 2019-12-05 17:16:11
I see it's simple to convert golang's big int (math/big package) to a string, but is there any straightforward way of converting a big int to a binary string? Should be as easy as this: i := big.NewInt(2014) s := fmt.Sprintf("%b", i) // 11111011110 fmt.Println(s) Hope this is what you are looking for. 来源: https://stackoverflow.com/questions/23317336/golang-big-integers-to-binary-string

How to work on big integers that don't fit into any of language's data structures

喜欢而已 提交于 2019-12-05 12:24:54
问题 I'm trying to solve a programming contest's preliminary problems and for 2 of the problems I have to calculate and print some very big integers(like 100!, 2^100). I also need a fast way to calculate powers of this big integers. Can you advice me some algorithms or data structures for this?(btw, I read C Interfaces and Implementations 'arbitrary precision arithmetic' section but it doesn't help for pow()) EDIT: I think exponentiation by squaring method and bit-shifting will work for power but

Alternative to BigInteger.ModPow(); in C#

半世苍凉 提交于 2019-12-05 08:04:45
问题 i'm looking for an alternative to the BigInteger package of C# which has been introduced with NET 4.x. The mathematical operations with this object are terribly slow, I guess this is caused by the fact that the arithmetics are done on a higher level than the primitive types - or badly optimized, whatever. Int64/long/ulong or other 64bit-numbers are way to small and won't calculate correctly - I'm talking about 64bit-integer to the power of 64-bit integers. Hopefully someone can suggest my

bigint truncated via PDO?

故事扮演 提交于 2019-12-05 03:50:49
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 this line of code: //parameterized query //update my_table set bigint_field = :bigint_field where id