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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:47:29+00:00 2026-06-07T12:47:29+00:00

I’m trying to make a simple text encrypter (not all functions are complete) but

  • 0

I’m trying to make a simple text encrypter (not all functions are complete) but I have a specific problem that I would like some help with. I stopped at this point in coding and added some commented documentation for testing:

In the function algorithm():
lines 16-25 are appending the index of std::string ck[] to std::string KEY inside the nested loop. The outside loop is running for the measure of PASSWORD.size() and checking each PASSWORD.substr(…) against all ck[].

The output, however, only turns out to be the index values of the first and last character of PASSWORD. eg. If PASSWORD=abc KEY outputs 0002. I want the whole PASSWORD to become KEY (as dictated).

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


std::string PASSWORD, KEY, ENCRYPTED_TEXT;

void algorithm(std::string note){
    ENCRYPTED_TEXT.append(note);

    /**STANDARD RULESET**/
    std::string ck[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    for(int x=0;x<PASSWORD.size();x++){
        for(int y=0;y<sizeof(ck)/4;y++){ 
            if(PASSWORD.substr(x,x+1)==ck[y]){
                std::stringstream ind;
                if(y>9) ind << y+1;
                else ind << "0" << y;
                KEY.append(ind.str());
            }
        }
    }
    std::cout << "\nKey is " << KEY;

    //make_file(ENCRYPTED_TEXT);
}

void qn_setup(){
    bool ask=true;
    while(ask=true){
        std::string check1="", check2="";
        std::cout << "Type a password:\n";
        std::cin >> check1;
        std::cout << "Confirm password:\n";
        std::cin >> check2;
        if(check1==check2) { 
            PASSWORD=check1;
            ENCRYPTED_TEXT=check1;
            ask=false; 
            break; }
        else { std::cout << "\nPasswords did not match.\n"; }
    }
}

int main(){
    qn_setup();
    algorithm(""); //testing key
}

There aren’t any syntax errors, just logic errors.

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

    string substr ( size_t pos = 0, size_t n = npos ) const;

    Generate substring
    
    Returns a string object with its contents initialized to a substring of the 
    current object.
    
    This substring is the character sequence that starts at character position 
    pos and has a length of n characters.
    

    so your check has to be:

    PASSWORD.substr(x,1)==ck[y] /* instead of PASSWORD.substr(x,x+1) */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in

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.