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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:43:42+00:00 2026-05-29T05:43:42+00:00

I am new to programming and sometimes even the stuff I write remains mysterious

  • 0

I am new to programming and sometimes even the stuff I write remains mysterious to me. This is my first time asking for help on the internet.

I have a problem here and I haven’t been able to solve it for some time now.

This is what I want to do:
Read byte by byte from a file into a vector, modify the bytes and write them back.

This is what happens:
All the encryption stuff seem to work, but somehow after several of these operations a part of the file goes missing.

In the byte modifying process I use char overflows, that means I add some random number to each part of my vector and write it back as a whole.

In my opinion this could be some kind of arithmetic overflow issue I don’t know about.

By the way, I use Qt SDK and Windows environment, in case that helps.

Here’s the code fragment:

void crypt(string * password,string filename, int sign){
    vector<char> stack;
    ifstream is;
    is.open(filename.c_str());
    char c;
    for (int i = 0; !is.eof(); i++){
        is >> noskipws >> c;
        stack.push_back(c);
    }
    stack.pop_back();
    is.close();
    int code = 0;
    double x;
    char method = 0;
    int var;
    for (int i = 0; i < password->size(); i++)
        code += password->at(i);
    for (int i = 0; i < (stack.size()); i++){
        // some unrelated stuff skipped
        if (sign == 1)code += stack[i];
        stack[i] += var*method*sign;    //<----this might be the cause!
        if (sign == -1)code += stack[i];
        method = 0;
    }
    ofstream os;
    os.open(filename.c_str());
    for (int i = 0; i < stack.size(); i++){
        os << noskipws << stack[i];
    }
    os.flush();
    os.close();
}

Sorry for the mess in the code, I kind of wrote it for testing.

Any ideas will be appreciated.

  • 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-05-29T05:43:44+00:00Added an answer on May 29, 2026 at 5:43 am

    You are opening your files in “text” mode, this can cause problems especially since your output characters will most certainly end up outside the range of printable ASCII characters. This can cause issues as on windows for example, when you try to output the value 0xD (carriage return), the library will convert that into a 0xD followed by 0XA (line feed).

    So, try to open your files in binary mode like this:

    os.open(filename.c_str(), ios::binary);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've came across this new acronym, SOFEA, apparently a new programming paradigm for web
I'm quite new to programming larger applications. I have now written a command line
I am still a bit new to Windows programming and sometimes find the documentation
When programming with C/C++ or Python I sometimes used to have a dictionary with
I am new to VB programming and have come across an problem:( after a
I have been programming C for a while (but still pretty new to C)
first of all I'm new to python and programming but you guys already helped
I am brand new to this community. I am also somewhat new to programming
I am new to programming with no formal programming training, so please excuse this
This has to be a common question that all programmers have from time to

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.