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

- 09-06-2010, 06:23 AMbobo67equation
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 AMZack
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.

- 09-06-2010, 07:50 AMbobo67
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 AMj2me64

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 PMJosAH
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 PMbobo67
Thanks a lot