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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:47:22+00:00 2026-06-13T05:47:22+00:00

I am having a terrible time understanding how to get the wrapper to work

  • 0

I am having a terrible time understanding how to get the wrapper to work with these encryption programs. I got a Caesar cipher program to work to both encrypt and decrypt, now I am working on a Vigenere cipher. I have the program working but when I use a key that will cause the letters to wrap around I get odd results. Here is the code I am using:

int main(int argc, char *argv[])
{
    char s2[25];
    strcpy(s2, argv[1]);
    printf("Please enter a string of text to be encrypted!\n");
    string p = GetString();
    for (int i = 0, n = strlen(p); i < n; i++)
    {
        if (isupper(p[i])){

        char c = (p[i] - 'A' + s2[i]);
        printf("%c", c);
        }
    }
    printf("\n");

}

This code will work if the command line input is ./program BACON and I enter BLAH for the text to be encrypted. If for example I use ./program ZZZZZ as the key then I will get all kinds of odd results because it does not wrap back around. I have tried using the modulus operator and have left it out of the code I just posted because I still could not get it to wrap with that. I am just starting to learn programming.

Update

Maybe you can help me understand the math better; your code works perfectly, but I have been trying to figure this out on a calculator manually just to see what’s going on. This is what I have so far:

./program HHHHH

keyLen should equal 5 in my understanding and so if I give p[i] a value of “H”

keyLen= 5
p[i]= H   //or 72 in ASCII 
int sum = (p[i] - 'A') + (s2[i % keyLen] - 'A'); //sum = (72 - '65') + ([72 % 5] - '65');
char c = 'A' + sum%26; // c = 65 + -11

Maybe my math is way off because when I do things in the order I think they should be done sum = negative 63 and so a 26 mod of -63 which gives me negative 11. Which clearly is not right because that equals 54 when you add 65 and negative 11.

Even if I make the negative 11 a positive integer of 11 and add 65 I get 76 which is ASCII character “L” but the right answer is “O”. I am clearly doing something wrong but I’ve been working on the solution for a while now and keep coming up with the same results.

  • 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-13T05:47:23+00:00Added an answer on June 13, 2026 at 5:47 am

    There are two “wrap-around” issues in your program:

    • Your letters do not wrap around when the key and the current letter combine to produce a value beyond 26, and
    • You read past the end of the key when the length of the word being encrypted exceeds the length of the key.

    Here is how you fix it: right after copying the key into s2, do this:

    int keyLen = strlen(s2);
    

    Now inside your loop do this:

    int sum = (p[i] - 'A') + (s2[i % keyLen] - 'A'); // Calculate the sum of key+word
    char c = 'A' + sum%26; // Wrap around at 26, the number of letters in the alphabet
    

    This will make the output look “normal”.

    Once you figure out how the last formula works, you should be able to modify it to decode the word.

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

Sidebar

Related Questions

I am having a terrible time trying to get an input box like the
I'm having a difficult time understanding how to get Rails to show an explicit
I am having a terrible time getting a webpage to work and could really
I am having a terrible time figuring this one out. I have a form.
I'm having terrible trouble trying to get a navigation controller up-and-running. Basically, I want
I'm having a terrible time trying to pull out some values out of an
I have been having a terrible time trying to compile a python extension -
My title is terrible but I'm having a hard time wrapping my head around
I'm having a terrible time convincing myself what I've done here is a good
I am having a terrible time getting my height of my DIVs to properly

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.