1. Member Join Date
Sep 2010
Posts
37
Rep Power
0

## 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  Reply With Quote

2. ## 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:
Java 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!).  Reply With Quote

3. Member Join Date
Sep 2010
Posts
37
Rep Power
0

## 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,  Reply With Quote

4. ##  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

Java 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

Java Code:
```		double d1 = 6.5;
double d2 = 3.0;
System.out.println(d1 % d2);```

and the output is 0.5.  Reply With Quote

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  Reply With Quote

6. Member Join Date
Sep 2010
Posts
37
Rep Power
0

## Thanks a lot  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•