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 9104963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:59:05+00:00 2026-06-17T01:59:05+00:00

hey i’m creating new project about cryptography here’s my code: private void encCaesar() {

  • 0

hey i’m creating new project about cryptography
here’s my code:

private void encCaesar() {

    char[] chars = plaintext.toCharArray();
    for (int z = 0; z < plaintext.length(); z++) {
        char c = chars[z];
        if (c >= 32 && c <= 125) {
            int x = c - 32;
            x = (x + keyCaesar) % 96;
            if (x < 0)
                x += 96;
            chars[z] = (char) (x + 32);
        }
    }
    tempCipher = new String(chars);
    Log.d("Caesar", tempCipher);  

}

private void encRF() {

    int skip;
    int i, d, j;

    for (d = 0; d < keyRF - 1; d++) {
        skip = 2 * (keyRF - d - 1);
        j = 0;
        for (i = d; i < tempCipher.length();) {

            ciphertext += tempCipher.charAt(i);
            if ((d == 0) || (j % 2 == 0))
                i += skip;
            else
                i += 2 * (keyRF - 1) - skip;
            j++;
        }
    }

    for (i = d; i < tempCipher.length(); i += 2 * (keyRF - 1)) {
        ciphertext += tempCipher.charAt(i);
    }
    Log.d("RF", ciphertext);  
    etCipher.setText(ciphertext);
}

btnEnc.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {

                keyRF = 2;
                String tempkey = key1.getText().toString();
                plaintext = etPlain.getText().toString();
                if (plaintext.trim().equals("")) {
                    {
                        AlertDialog alertDialog = new AlertDialog.Builder(
                                SentSMSActivity.this).create();
                        alertDialog.setTitle("Alert Dialog");
                        alertDialog
                                .setMessage("Plain text masih kosong . . .");
                        alertDialog.setButton("OK",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog,
                                            int which) {
                                    }
                                });

                        alertDialog.show();
                    }

                }
                if (tempkey.trim().equals("")) {
                    Toast.makeText(
                            getBaseContext(),
                            "Key 1 masih kosong, maka akan digunakan digunakan key default yaitu 2",
                            Toast.LENGTH_SHORT).show();
                    key1.setText("2");
                } else if (Integer.parseInt(tempkey) > plaintext.trim()
                        .length() - 1) {
                    Toast.makeText(
                            getBaseContext(),
                            "Key 1 nilainya melebihi plaintext, maka akan digunakan digunakan key default yaitu 2",
                            Toast.LENGTH_SHORT).show();
                    key1.setText("2");
                } else {
                    keyRF = Integer.parseInt(key1.getText().toString());
                }

                keyCaesar = 3;
                if (key2.getText().toString().trim().equals("")) {
                    Toast.makeText(
                            getBaseContext(),
                            "Key 2 masih kosong, maka akan digunakan digunakan key default yaitu 3",
                            Toast.LENGTH_SHORT).show();
                    key2.setText("3");
                } else {
                    keyCaesar = Integer.parseInt(key2.getText().toString());
                }

            } finally {

                tempCipher = "";
                encCaesar();
                encRF();

            }
        }
    });

when click encrypt, encrypt Caesar first then RF.
i have done opposite RF then Caesar just work fine
but when caesar then RF problem comes up
so the problem is when the ciphertext supposed to be “XYZ” but instead it appear “nullXYZ”

  • 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-17T01:59:07+00:00Added an answer on June 17, 2026 at 1:59 am

    null String gets ‘null’ when converted toString. Try initialize your String variable with

    String ciphertext = "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
Hey Guys If I do this in mono touch: var alert = new UIAlertView
Hey all. Okay here is the situation. I would like to be able to
hey guys, I'm totally inexperienced in terms of threads, so here's my question: How
Hey guys so I'm a bit new to Android programming and I have an
Hey Guys Here is the URL of my website http://www.avmsolutionsuk.com/ thats opening in Quirks
Hey I am new to github so please help me out. I have four
Hey all. I'm trying to see about handling events in a console application. I
Hey all, I'm using this code to change my sIFR (version 3) H1 and
Hey all. I'm working on a project for school where I need to pass

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.