Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8979231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:48:10+00:00 2026-06-15T19:48:10+00:00

I am playing around with simple encryption using RSA algorithms and found a strange

  • 0

I am playing around with simple encryption using RSA algorithms and found a strange bug.

private static Integer testEnc(Integer value){
    Integer val = (int)Math.pow(value, 37);
    return val % 437; 
}

private static Integer testDec(Integer value){
    Integer val = new Integer((int)Math.pow(value, 289));
    return val % 437;
}

public static void main(String[] args) {
    System.out.print("Encode 55  = ");
    Integer encoded = testEnc(2);
    System.out.println(encoded + "\n");

    System.out.print(encoded + " decoded = ");
    Integer decoded = testDec(3977645);
    System.out.println(decoded + "n");
}

Both of the following functions return 97 regardless of input. If I comment out the modulus and just return val, the returned value is 2147483647.

Type casting double to int seems to be the issue but I am not sure why this is.
These methods are static only because I was calling them from a main method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:48:11+00:00Added an answer on June 15, 2026 at 7:48 pm

    2147483647 is the int max value, aka 2^31-1.
    For any value >=2 you get an overflowm because 2^37 > 2^31-1

    In order to get the power modulo 437 you should get the modulo at every step. E.g. like:

    private static int myPow(int a, int b, int mod){
        int ret = 1;
        for(int i = 0; i < b; i++)
        {
            ret = (ret * a) % mod;
        }
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was playing around making a simple haiku site using sqlalchemy and pylons. It
I have a very simple repository I'm playing around with, using Entity Framework v4
I'm playing around with using ASP.NET MVC3 and have a very simple site that
I have been playing around with a simple application for Windows Phone 7 using
I'm playing around with using Simple.Data for my next project, and ran across something
I am playing around trying to call a simple SOAP webservice using the following
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
I was playing around with recursion and did this simple function. I was assuming
I'm playing around with writing some simple Spring-based web apps and deploying them to
I am playing around with trying to make a simple Roguelike game to learn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.