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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:12:03+00:00 2026-06-15T12:12:03+00:00

I’m writing a program for Vigenere Cipher. But I don’t know how to make

  • 0

I’m writing a program for Vigenere Cipher. But I don’t know how to make my key repeat til the end of my plain text. Right now what my code does is encrypt only the letters which are equivalent to the number of letter my key has. For example I enter a key of “dog” and my plain text is “catdog”, it gives me an encrypted text of “fozdyw”. Which means it is only encrypting the first 3 letters.

This is a bit of my code that does the encrypting:

for (int j=0, k=0; j < strlen(text); j++, k++)
      {         
        if((text[j] >= 'A') && (text[j] <= 'Z'))
            text[j] = ((text[j] -'A') + key[k]) % 26 +'A';

        if((text[j] >= 'a') && (text[j] <= 'z'))
            text[j] = ((text[j] -'a') + key[k]) % 26 +'a';

        printf("%c", text[j]); 
      }  

What am I doing wrong? And what should be the right thing to do?

  • 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-15T12:12:04+00:00Added an answer on June 15, 2026 at 12:12 pm

    When you get to the end of the key, go back to index 0, this is done by using the remainder of the division by the size of the key (AKA modulus):

      for (int j=0, k=0; j < strlen(text); j++, k++)
      {         
        if((text[j] >= 'A') && (text[j] <= 'Z'))
            text[j] = ((text[j] -'A') + key[k % size_of_the_key]) % 26 +'A';
    
        if((text[j] >= 'a') && (text[j] <= 'z'))
            text[j] = ((text[j] -'a') + key[k % size_of_the_key]) % 26 +'a';
    
        printf("%c", text[j]); 
      }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question

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.