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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:08:27+00:00 2026-06-18T11:08:27+00:00

Help! I’m trying to figure out this code our professor gave us – #include

  • 0

Help! I’m trying to figure out this code our professor gave us –

#include <stdio.h>
#include <string.h>

void encrypt(int offset, char *str) {

    int i,l;

    l=strlen(str);

    printf("\nUnencrypted str = \n%s\n", str);

    for(i=0;i<l;i++)
        if (str[i]!=32)  
            str[i] = str[i]+ offset;

    printf("\nEncrypted str = \n%s \nlength = %d\n", str, l);
}

void decrypt(int offset, char *str) {

    // add your code here
}

void main(void) {

    char str[1024];

    printf ("Please enter a line of text, max %d characters\n", sizeof(str));

    if (fgets(str, sizeof(str), stdin) != NULL)
    {
        encrypt(5, str);    // What is the value of str after calling "encrypt"?

        // add your method call here:
    }
}

We are suppose to do the following:

  • Convert the C code to C++.

  • Add codes to the “decrypt” method to decipher the encrypted text.

  • Change the code to use pointer operations instead of array operations to encrypt and decrypt messages.

  • In the main method, call the “decrypt” method to decipher the encrypted text (str).

This is as far as I managed to go, but I’m pretty much stuck now. Especially since I have no background in the C language. Any help would be appreciated.

#include <iostream>
#include <string.h>

void encrypt(int offset, char *str)
{   
    std::cout << "\nUnencrypted str = \n" << str;

    char *pointer = str;

    while(*pointer)
    {
        if (*pointer !=32)  
            *pointer = *pointer + offset;
        ++pointer;
    }

    std::cout <<"\nEncrypted str =\n" << str << "\n\nlength = ";
}

void decrypt(int offset, char *str) {

    // add your code here
}

void main(void) {

    char str[1024];

    std::cout << "Please enter a line of text max " << sizeof(str) << " characters\n";

    if (fgets(str, sizeof(str), stdin) != NULL)
    {
        encrypt(5, str);    // What is the value of str after calling "encrypt"?

        // add your method call here:
    }
}
  • 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-18T11:08:28+00:00Added an answer on June 18, 2026 at 11:08 am

    The code you posted should work in C++ as well as C. There shouldn’t be a need to “convert” anything, unless there are specific requirements that you haven’t told us about.

    Your array-to-pointer conversion looks correct, although I would argue that the code is more readable in the array form.

    For your decrypt method, you will want to write code that does the inverse of what the encrypt method does. The best way to approach this is to run some sample text through encrypt and examine what the output looks like. The function transforms the input a single character at a time, so you should be able to map input to output on a byte-by-byte basis. With this information, you can detect the pattern and construct a function that makes the transformation in the other direction.

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

Sidebar

Related Questions

help me figure out how to set an event on the parent element (
Help me understand this piece of code - After the first iteration the value
Help will be most appreciated. This is the code from the Jquery website <button
Help me to understand how this code works. It essentially adds commas into a
Help me understand the last portion of this code that aims to print the
Help me to create an XML format like this : http://telkomvision.com/soap/timetable/monday.xml The code that
Help me with my code, because i don't now how to do this simple
Help me figure out why isn't my form getting styled a la sites/all/modules/pecapture/themes/pecapture-displayform.tpl.php Here's
Help me translate following block of the Haskell code. The run function produces text
Help from the SQL Gods Required Table 1 - DistinctQuotes This tables holds information

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.