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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:22:50+00:00 2026-06-01T00:22:50+00:00

I was trying to do a Vigenere cipher program in java, and I encountered

  • 0

I was trying to do a Vigenere cipher program in java, and I encountered some problem with the encryption/decryption part of the code. I know how I should go about approaching the encryption/decryption, but I am having trouble putting that into code.

Let me start off by explaining the project:

For this project, I am creating a cipher program (Vigenere cipher is different than caesar cipher in that Vigenere allows the key to be a word rather than just a letter or number) that first prompt the user if he/she wants to encrypt or decrypt a message. Once the user makes the selection, the program prompts the user for a “key”. the key has to be lower case, and a word, not symbols or numbers. Then the program will ask the user for an input file that contains the message the user wants to decrypt or encrypt. Afterward, the program prompts the user for an output file name and store the decrypted/encrypted message in that file.

So let’s say the message is “Meet at 567” and the key is cats, and the user want to encrypt the message, the output should end up like “Oexl ct 567”

The encryptLine/decryptLine method of my code only needs to encrypt/decrypt one line of text. the other parts of my code will take care of other lines. For the code that I have done so far, the decryptLine is completely wrong, right now, I just want to focus on the encryptLine. Once I figure that out, figuring out the decryptLine shouldn’t be so hard. In the following, I have post comments in my encryptLine method as to what I am trying to do. The encryption works, it just has trouble when it encounter a space or symbols such as ?&%$. I know it has a lot of redundant code, but it is the best things I could come up with since I am new at this.

Thank you in advance for your help!!!

  • 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-01T00:22:51+00:00Added an answer on June 1, 2026 at 12:22 am

    The problem is that, when you’re processing position i within line, you’re expecting to be able to compute the position within key based on i. This makes sense — key.charAt(i%(key.length()+1)) is almost correct (though it actually would have to be key.charAt(i%key.length()), without the +1, since the valid positions in key range from 0 to key.length()-1) — but it won’t work for you, because you want certain characters not to “count”, that is, you don’t want them to “use up” a character in the key. So your position within key is actually somewhat independent of i, in that it also depends on what types of characters you’ve already seen in line.

    So really what you need is to have a completely separate index, j, within key. Every time you process a letter from line, you increment j. You can then either use the modulus approach, and write key.charAt(j%key.length()), or else simply reset j to 0 every time it would otherwise be key.length().

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

Sidebar

Related Questions

I am trying to do a Vigenere cipher program, but I am having some
Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying to generate a lazily iterable collection of Vigenere cipher keys of length
Trying to parse an HTML document and extract some elements (any links to text
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
Trying to write this small program to help me in my Stats class, everything
Trying to find some information on this but am unable to get any results
Trying to reproduce the problem from this question , I've found I can't plot
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to find some simple SQL Server PIVOT examples. Most of the examples that

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.