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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:24:32+00:00 2026-06-01T03:24:32+00:00

I am trying to do a Vigenere cipher program, but I am having some

  • 0

I am trying to do a Vigenere cipher program, but I am having some trouble with the decrypting part of the code. The funny thing is that I thought if I got the encrypting part of the code to work, the decrypting, would just be reverse. For the most part, it is, but there is just one tiny problem.

Let me start off by explaining what the program is trying to do:
My whole program is to get a text file from the user, and a key word( has to be letters and lower cases) and shift the individual letters of that text file to certain positions according to the key word. For this decryption part of the code, I only need to decrypt a single line, the other part of the program will take care of keep decrypting until it reaches the end of the text file. For simplicity, let’s say the text is “oexl” and the key is “cats”, if the decryption works, the result should be “meet”, but instead my code ends up with “meeZ”

I know what went wrong, but I am not really sure how to fix it. I tried various ways, and the end results kept getting worse.

for the problem part of the code, I tried replacing it with this for the if statement

Character.isLetter(text2) && line.charAt(i) >= 97 && line.charAt(i) <= 122 && text1 >=65 && text1 <=90

That didn’t work.

Another idea that I came up with is an if statement that is first testing to see if the the original character from the text is a letter, if it is, subtract that character by the shift position and if that number is less than 97 (this is the ascii value for a), then add 25 to that number to bring it to z. For example. let’s say the original letter is l ( ascii value 108), key is s (ascii value 115, sutract that number by ascii value of a ( 97), the result 18, that means the letter has to shift by 18 position). What I do next is subtract 18 from 108(l), I get 90. Afterward, I compare this number to 97 (ascii value for lower case a) Since 90 is less than 97, what the program should do is add 25 to 108, which I get 133. Subtract 113 by 18(the number of places the text needs to shift), I get 116, which is ascii value for t. The problem is, I am not really sure how to implement this code.

Thank you very much in advance for your help.

        if (Character.isLetter(line.charAt(i))){


        int text1 =  line.charAt(i) - (key.charAt(j%(key.length()))-'a');  

        char text2 =(char)text1;
        String text3 = Character.toString(text2);
        text4 += text3;
        System.out.println(text4);


        if (text1<= 65 || (text1 >90 && text1 <97)) {
        text1 = text1 + 26;
         text2 =(char)text1;
         text3 = Character.toString(text2);
        text4 += text3;

        }
        j++;
  • 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-01T03:24:33+00:00Added an answer on June 1, 2026 at 3:24 am

    Your condition just needs to check if the character was lowercase and is now < ‘a’, or was uppercase and is now < ‘A’:

    if (text1 < 'A' || (text1 < 'a' && line.charAt(i) > 'a')) {
        text1 = text1 + 26;
        text2 = (char)text1;
        text3 = Character.toString(text2);
        text4 += text3;
    }
    

    Edit: I’d fit it in with the rest of the loop like:

    for(int i = 0; i<= line.length()-1; i++) {
        if (Character.isLetter(line.charAt(i))) {
            int text1 =  line.charAt(i) - (key.charAt(j%(key.length()))-'a');  
    
            if (text1 < 'A' || (text1 < 'a' && line.charAt(i) > 'a')) {
                text1 = text1 + 26;
            }
            text4 += (char)text1;
            j++;
        } else {
            text4 += line.charAt(i);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to do a Vigenere cipher program in java, and I encountered
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I'm trying to generate a lazily iterable collection of Vigenere cipher keys of length
Trying to find some information on this but am unable to get any results
trying to work out how to install zipArchive extension with MAMP, but not having
Trying to send a complex type between two systems that have the same code
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to make a make generic select control that I can dynamically add elements
Trying to perform a single boolean NOT operation, it appears that under MS SQL

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.