hi,
I don't know how to write this equation in java, which [b^e mod n] is RSA encryption.
my equation is: [m * (b^e)] mod n
Printable View
hi,
I don't know how to write this equation in java, which [b^e mod n] is RSA encryption.
my equation is: [m * (b^e)] mod n
Take firstly into consideration that the symbol for modulus (mod) is a percent sign (%). Secondly, remember that in Java [] is used for array features. You will have to use layered ()s. That is to say:
And, finally, to do x^y (x to the power of y), you will want to look at Math.pow(), as ^ in Java is a bitwise operator (not what you're looking for here!).Code:int x = [7 + 5 * (6 + 2)] * 7; // Invalid.
int y = {7 + 5 * (6 + 2)} * 7; // Invalid.
int z = (7 + 5 * (6 + 2)) * 7; // VALID.
I wrote a function for RSA encryption, which calculate b^e mod n. As you know e is public exponent and n is module.
but I have an equation that a public key multiply b^e.
I don't know how to implement this.
regards,
for b^e you can use this example
Code:double b = 3.0;
double e = Math.E;
System.out.println(Math.pow(b, e));
and i assume module is the modulo in java, so use the % as modulo. in the following example the modulo of 6.5 mod 3.0 is calculated
Code:double d1 = 6.5;
double d2 = 3.0;
System.out.println(d1 % d2);
and the output is 0.5.
Don't use the Math.pow( ... ) method; have a look at the BigInteger class, it implements the modPow( ... ) method and much more efficient than a general pow( ... ) method can do.
kind regards,
Jos
Thanks a lot