Results 1 to 6 of 6

Thread: equation

  1. #1
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Unhappy 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

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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!).

  3. #3
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Unhappy

    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,

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by bobo67 View Post
    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.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default

    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

  6. #6
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

Similar Threads

  1. Need help with math equation
    By annabellastorm in forum New To Java
    Replies: 4
    Last Post: 01-10-2010, 05:12 PM
  2. differential equation RK4
    By arvindmer in forum New To Java
    Replies: 3
    Last Post: 01-08-2009, 01:27 PM
  3. Quadratic Equation
    By jpnym15 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 03:29 AM
  4. Help with an equation in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:47 AM
  5. Problem with equation in my algorithm
    By romina in forum New To Java
    Replies: 2
    Last Post: 07-20-2007, 07:53 AM

Posting Permissions

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