# equation

• 09-06-2010, 06:23 AM
bobo67
equation
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
• 09-06-2010, 07:42 AM
Zack
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:
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.```
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!).
• 09-06-2010, 07:50 AM
bobo67
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,
• 09-06-2010, 11:07 AM
j2me64
Quote:

Originally Posted by bobo67
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.
• 09-06-2010, 12:29 PM
JosAH
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
• 09-06-2010, 06:40 PM
bobo67
Thanks a lot