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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:27:41+00:00 2026-06-04T02:27:41+00:00

My decipher program is not working correctly… public static void decipherMessage() { Scanner sc

  • 0

My decipher program is not working correctly…

  public static void decipherMessage() { 

    Scanner sc = new Scanner(in);

    System.out.println("Enter keyword: "); 
    String decipher = sc.nextLine(); 

    String plain = ("abcdefghijklmnopqrstuvwxyz"); 
    String cipher = decipher + "abcdefghijklmnopqrstuvwxyz";

    System.out.println("Enter enciphered message: ");
    String ciphMsg = sc.nextLine(); 

    String decipherMessage = ciphMsg.toLowerCase();

    char[] chars = cipher.toCharArray();
    Set<Character> charSet = new LinkedHashSet<Character>(); 

    for (char c : chars) {
        charSet.add(c);
    }

    StringBuilder cMap = new StringBuilder();
    for (Character character : charSet) {
        cMap.append(character);
        StringBuilder original = cMap;

    }
    for (int i = 0; i < 26; i++)
    {
        char cipherTextChar = cMap.charAt(i);
        char plainTextChar = plain.charAt(i);

        decipherMessage = decipherMessage.replace(cipherTextChar,plainTextChar); 

        System.out.println("Deciphered message");  
        System.out.println(decipherMessage);


    }

plain text letters are supposed to replace ciphered letters

but when I run it, it just gives the ciphered message again without deciphering?

example.

keyword: stack

plain : abcdefghijklmnopqrstuvwxyz

cipher: stackbdefghijlmnopqruvwxyz

message: overflow

ciphered message: mvhpbimw

except in reverse.
using the code I showed above it just gives the ciphered message again without deciphering anything.

  • 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-04T02:27:42+00:00Added an answer on June 4, 2026 at 2:27 am

    Your code does replace characters, just not correctly (assuming that the usage of deciphMsg and decipherMessage above is a typo. They should be the same variable.)

    Well one problem is that you’re doing string replacement one cypher character at a time.

    For example, if my cypher is “b”, it is supposed to switch all the a’s and the b’s, but if I give it the string

    abababababab
    

    first it will replace all the a’s by b’s giving

    bbbbbbbbbbbb
    

    and then replace all the b’s by a’s:

    aaaaaaaaaaaa
    

    which is not the intended outcome.

    The solution basically boils down to doing the replacement one message character at a time. You’ll have to loop over the message for that. You could also use a map to make it efficient.

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

Sidebar

Related Questions

I have a make build system that I am trying to decipher that someone
im new to regular expressions and would like to decipher this. return preg_replace(/[<>]/, '_',
i am really not able to figure this out myself so please help me
I have a system that receives requests encoded with 2 different public keys and
I have built a Program to decipher shift ciphers (Cesar Cipher). It seems to
I'm making a enciphering/deciphering program using XTEA algorithm. The encipher/decipher functions work fine, but
I am trying to make a program that Encrypts data using AES, then encrypts
Here's an example of what I mean... User runs LOADER.EXE program LOADER.EXE downloads another
Trying to decipher some Excel formulas and I see some stuff like SUMPRODUCT(--Left(...)...) What
I am trying to decipher some SQL statements using, SQL Profiler, that are run

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.