Ethereum: Step -by -Step Muzzle Pow_mod256
In the fixedness of the function Pow ()
Used for combing two modular exponents. It is possible to be spreading for the finished tasks, this is not always the most efficient or stylish resolution. In this state, we study how you can translate similarly: pow_mod256.
What isPow_mod256?
Pow_mod256scatters two -digit module 2^256 modular exponents. This function covers the general function of the Euler, which cleanses the number of whitels of the body to the defined chapter, which is important for it.
RealizePow_mod256Solid?
Let's overcome, why would we want to use this function, pre -unite in the realization:
- In the defined cryptographic attachments, the modular indicator is not necessary for the non -peculiar healing.
- The eelization of euler can be difficult and entering.
pow_mod256realeization of the strong
Here is a high level of high levels, as you can realize "pow_mod256".
Pragman solitude ^0.8,0;
Convention Modularexpontenation {
Function Pow_mod256 (Uint256 B, Uint256 M) SCIENCE (UINT256) {
// Formatory Result to value 1
Uint256 Result = 1;
// Read the modular multi -artistic “B” Modulo ‘M’
Uint256 modulus = modpow (M – 2, M);
// Uspolzing the reinforced function Pow ()
from -wit the efficiency
Return Pow (B, M-2, M) * Module;
}
Functional (Uint256 A, Uint256 B) Intramentous Clean Avaiures (Uint256) {
IF (B <= 1) {
Returns A;
}
/
Uint256 phi = m-1;
Uint256 g = pow (A, Phi, M);
Return Pow (G, B, M);
}
}
`
Enlightenment
In this reality:
- We have a heard of the meaning of “Result” 1. This is used in the quality of the selection point for our comb.
- We cleanse the modular lining layer “B” M ‘M’ M ‘M’ M ‘M’ M ‘M’ M ‘M’ M ‘M’ M’MALL SUPPLIATION OF FERMAT (SUPPOSE FERMAT SUPPOSITIES that for every shadow “a^(Mod) m), where phi (m)) is a common function of Euler). In this case, we use the formula
A^PHI (M) ≡ 1 (MOD M) for combing.
- Pass the reinforced functionPow ()
for efficiency. This function enters the three argument: basic, exponent and module. Using the M-2
indicator, not only one, we can escape the non-unintentional comb.
Prime Variants Uspolzing
Now you can use this realization in your firm counterattures to easily discard modular shows:
`
Agreement MyContract {
Function Pow_mod256 (Uint256 B, Uint256 M) SCIENCE (UINT256) {
Return to Modularexponenation.pow_mod256 (B, M);
}
}
`
Such an image, pow_mod256
is a blank function for combing modular indicators. It is not so simple to realize how other functions, such as Add
or Podbadri, is the realization of the effective and stylistic.
Entertainment : This realization prefare that you use 0.8.0 or more late. If you use the pre -trial version, you can use the second sub -biblothek for combing modular indicators.