Can You Solve This Big Integer Problem?

Update: I solved it … I just had to parse:

Can You Solve This Big Integer Problem?

Update: I solved it … I just had to parse:

$val=[BigInt]::Parse("1111111111111111111")
$val

On ASecuritySite, I have lots of examples of Python, Golang, Node.js, and JavaScript, so I have been converting a range of cryptography examples into PowerShell. The core advance of using PowerShell is that it can gain access to the .NET framework, and can run in a scripted way. It is also fairly fast in its operation and is fairly robust. If you want to see these examples, try here:

https://asecuritysite.com/powershell/

In cryptography, we often use integers which are much larger that the 64-bit ones supported by most compilers. Thus we turn to Big Integers, and which can be of any length. For example, we can perform the operation of $a to the power of $d, mod $n, with:

$x= [System.Numerics.BigInteger]::ModPow($a, $d, $n);

And, so I was working on a program to test for a prime number, and which uses the Miller-Rabin method. Everything works well, but I hit a problem when I parse a string value which represents an integer, and where I receive an incorrect value for the Big Integer value. The code is here:

https://asecuritysite.com/powershell/rab

But, when I pass large integer values, it gives me an incorrect version. So, I ran on my Mac and on Windows, and both gave me the same error conversion. To illustrate here is a conversion:

PS powershell> $prime=[BigInt]::new("11111111")
PS powershell> $prime
11111111
PS powershell> $prime=[BigInt]::new("111111111111")
PS powershell> $prime
111111111111
PS powershell> $prime=[BigInt]::new("11111111111111111111")
PS powershell> $prime
11111111111111110656
PS powershell> $prime=[BigInt]::new("111111111111111111111111")
PS powershell> $prime
111111111111111109246976
PS powershell> $prime=[BigInt]::new("11111111111111111111111111111")
PS powershell> $prime
11111111111111111869590405120

Does anyone know how to fix this? I have not faced this problem with any other programming langauge, and should be able to convert from an integer string value, to a Big Integer.

To run PowerShell on your computer, just open up a command line prompt or a terminal and run “pwsh”. The prompt should change to “PS …”.