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

  • SEARCH
  • Home
  • 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 6078877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:52:58+00:00 2026-05-23T10:52:58+00:00

I have written code to send encrypted message. But the encrypted data SMS is

  • 0

I have written code to send encrypted message.
But the encrypted data SMS is not delivering because onrecive() methode is not invoking . I think I have problem in receiver part.

Now, I am new in android.. Any body help me what is the wrong with the following code (I am using RSA algo)? Thanks in advance……..

For Sending:

public class MainMethod extends Activity 
{
    Button btnSendSMS;
    EditText txtPhoneNo;
    EditText txtMessage;
    Button stop ;
    static boolean bombing = false;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
        txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
        txtMessage = (EditText) findViewById(R.id.txtMessage);

        btnSendSMS.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                try{
                   KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5");
                    SecretKey MD5key = keyGen.generateKey();
                    FileOutputStream fos = openFileOutput( "MD5key.txt" ,Context.MODE_WORLD_READABLE);
                    fos.write(MD5key.getEncoded());
                }
                catch(Exception e) {
                    ;
                }
                    String phoneNo = txtPhoneNo.getText().toString();
                    String message = txtMessage.getText().toString();
                    if (phoneNo.length()>0 && message.length()>0)
                    {
                        try{
                        stop = (Button)findViewById(R.id.btnSendSMS);
                        BigInteger ptext = new BigInteger(message.getBytes());  
                        BigInteger ciphertext = encrypt(ptext);
                        message = ciphertext.toString();
                        stop.setText("Message Sent");
                            SMSbomb(phoneNo,message  );
                        }
                        catch(Exception e) {
                            ;
                        }
                        }
                    else
                    {
                         stop = (Button)findViewById(R.id.btnSendSMS);
                        stop.setText("Send Properly");
                        Toast.makeText(getBaseContext(), "Please enter both phone number and message.", Toast.LENGTH_SHORT).show();
                    }

            }
        });        
    }


    private void SMSbomb(String phoneNumber, String message)
{
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";
        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context context, Intent intent) 
            {

                switch (getResultCode())
                {   
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show();
                        stop.setText("Proceeding");
                        break;

                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show();
                        MainMethod.endBombing();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show();
                        MainMethod.endBombing();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show();
                        MainMethod.endBombing();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show();
                        MainMethod.endBombing();
                        break;
                }
            }
        }, new IntentFilter(SENT));

        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        stop.setText("Send Message");
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendDataMessage(phoneNumber , null, (short) 3492, message.getBytes(), sentPI, deliveredPI);
        stop.setText("Send Message");
    }
    public static void endBombing()
    {
        bombing = false;
    }
    public static synchronized String encrypt(String message) {
        BigInteger e = new BigInteger("e") ;
          BigInteger n = new BigInteger(n");
        return (new BigInteger(message.getBytes())).modPow(e, n).toString();
      }

      public static synchronized BigInteger encrypt(BigInteger message) {
          BigInteger e = new BigInteger("e") ;
          BigInteger n = new BigInteger("n");
        return message.modPow(e, n);
      }
    }

//////////

For Receiving:

public class SmsReceiver extends BroadcastReceiver
{

private static final String TAG = "MySmsReceiver";


public void onReceive(Context context, Intent intent) 
{
    Log.i(TAG, "Recieved a message");

    String ds = "" ;
    //---get the SMS message passed in---
     Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdusObj = (Object[]) bundle.get("pdus");
            SmsMessage[] messages = new SmsMessage[pdusObj.length];

            // getting SMS information from PDU
            for (int i = 0; i < pdusObj.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
            }

            for (SmsMessage currentMessage : messages) {
                if (!currentMessage.isStatusReportMessage()) {
 String messageBody = currentMessage.getDisplayMessageBody();

                        byte[] messageByteArray = currentMessage.getPdu();

                        // skipping PDU header, keeping only message body
                        int x = 1 + messageByteArray[0] + 19 + 7;

                        String str = new String(messageByteArray, x, messageByteArray.length-x);
                        ds = currentMessage.getOriginatingAddress() ;

        //---display the new SMS message---
        String plaintext = decrypt(str);
    String plaintext1 = "SMS from " + ds + " Message " + plaintext ;


       Toast t =  Toast.makeText(context, plaintext1, Toast.LENGTH_LONG);  
       t.setDuration(30);
       t.setGravity(Gravity.CENTER_VERTICAL, 50, 50);
       t.show();
                }
            }

    }                         
}

//Here e and n are RSA’s shared secret.
public static synchronized String decrypt(String message) {
String ds = “e” ;
String ns = “n” ;
BigInteger d = new BigInteger(ds) ;
BigInteger n = new BigInteger(ns) ;
return new String((new BigInteger(message)).modPow(d, n).toByteArray());
}

      public static synchronized BigInteger decrypt(BigInteger message) {
          String ds = "e" ;
        String ns = "n" ;
         BigInteger d = new BigInteger(ds) ;
         BigInteger n = new BigInteger(ns) ;
        return message.modPow(d, n);
      } 

}
  • 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-05-23T10:52:58+00:00Added an answer on May 23, 2026 at 10:52 am

    You only need to register your receiver once.
    Register the receivers that you have in SMSbomb(phoneNo,message ); in onCreate() instead.
    I hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a code for sending sms to the friend but now I
I have written some code in my VB.NET application to send an HTML e-mail
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I have written C# code for ascx. I am trying to send an email
I have written some simple code, to send en auto generated email, using the
I have recently written some code which schedules messages to send to one of
I have written this code for a Message Receiving class that uses a backgroundworker
Hi I have written such a code below but it returns wrong output which
I have currently written code to send an email in C# using the usual
I have written code that automatically creates CSS sprites based on the IMG tags

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.