- Home /
System.Numerics.BigInteger in Unity 5.6
I am implementing an SRP6 algorithm to connect from my Unity 5.6+ client to a MMO Server I have been writing. I have the connection working in a client test application but I don't know how I can implement BigInteger in unity.
Using Unity 5.6 I was hoping it might implement a version of mono that supports System.Numerics, but I don't know how to add a reference to the assembly.
I have also tried using Scott Garland's BigInteger class, but it doesn't have some important functionality and I am not sure how to add a ModPow function to get it working.
Is it now possible to use System.Numerics and if so how? Or is there another library which would be a good alternative that includes the functionality needed?
Answer by Slatey · May 02, 2017 at 12:37 PM
I managed to figure out a ModPow function so with some modifications to Scott Garland's BigInteger class I am now able to use it exactly the same as I am using System.Numerics.BigInteger.
Below is the ModPow code I added to the BigInteger class.
public static BigInteger ModPow(BigInteger number, BigInteger exponent, BigInteger modulus) {
if (exponent < 0) throw new ArgumentOutOfRangeException("exponent");
if (modulus <= 0) throw new ArgumentOutOfRangeException("modulus");
if (exponent == 1) return number % modulus;
BigInteger result = new BigInteger(1);
BigInteger factor = new BigInteger(number.ToString());
BigInteger remaining = new BigInteger(exponent.ToString());
while (remaining != 0) {
if ((remaining & 1) == 1)
result = (result * factor) % modulus;
remaining >>= 1;
factor = (factor * factor) % modulus;
}
return result;
}
Your answer
Follow this Question
Related Questions
References and Namespaces 0 Answers
Adding Game Assembly causes type or namespace errors 0 Answers
Unity/C# Added assembelies, MonoDevelop builds, Unity won't run 0 Answers
Adding assembly references and additional project in MonoDev is not being saved when reopening Unity 2 Answers
Is there any overhead when using Update functions for making object references? 1 Answer