-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math/big: z.Exp(x, y, m) does not return, stuck in a dead loop #40421
Comments
Are you sure its stuck forever and not just taking a long time? |
|
Using ivy, we can easily calculate its logarithm base 2:
So the number is 2 to the power of that, or 2**41,481,054,344.5 or 10 to the power of 12,487,041,609.5, more than 12 billion decimal digits. Your machine needs 41.4/8 or 5.2GB of memory just to hold the result. As is explained above, you really need much more than that, and converting it to decimal to print it.... well, it won't happen today. |
Does computing this number came up in a real world scenario or is based on some LeetCode question asking about the last digits of the result of this exponentiation? |
Thank you so much for your reply. Respect. |
https://github.com/rqg0717/Homomorphic-encryption/tree/master/Cryptosystem/golang it is a real world scenario. Thank you. |
Yes, we have not faced any issue using C# in https://github.com/rqg0717/Homomorphic-encryption |
Your C# example is using https://en.wikipedia.org/wiki/Modular_exponentiation, not computing the exponent directly, which is the only way to achieve this in a reasonable time period for crypto purposes. |
In C# you're doing the modular reductions as the computation proceeds
In Go, you're doing all the math first and then the modular reduction.
I believe this should be
|
You are absolutely right! Thank you very much and sorry for the trouble. |
You are absolutely right! Thank you very much and sorry for the trouble. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
func main() {
z := big.NewInt(0)
x := big.NewInt(54493)
y := big.NewInt(2636432291)
z.Exp(x, y, nil) <- program stuck at here, running forever and does not return...
fmt.Println("result: ", *z)
}
What did you expect to see?
expect to see z = x**y
What did you see instead?
nothing...
The text was updated successfully, but these errors were encountered: