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

  • Home
  • SEARCH
  • 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 7534127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:55:37+00:00 2026-05-30T05:55:37+00:00

EDIT: SOLVED. zvbra appears to be right. giving only 4 chars to crypt was

  • 0

EDIT: SOLVED. zvbra appears to be right. giving only 4 chars to crypt was causing the problem. Gotta see why is that because i was told getline discarded the last character…

Hello fellow stackers.

I want to start by saying I tried to debug and solve my problem by myself but (probably due to my lack of knowledge on assembly and pretty much anything in general) i failed at doing so.
So I’ve came here in the hope you will be able to help me 🙂 .

I decided to code a simple (I think) encryption program, more of a test than anything else.

It’s divided in 2 parts:

Alghorithm.h (Yeah, I know it’s misspelled.) which contains class ‘Crypter’

#include <iostream>
#include <cmath>
using namespace std;

class Crypter
{
private:
    char Crypt[4];

public:
    Crypter()
    {
        getCrypt:
        cout<<"\nEnter a 4 character password: ";
        cin.getline(Crypt,5);
        if (cin.fail())
        {
            cout<<"\n\nError while reading password. 4 CHARACTERS MAXIMUM.\n\n";
            cin.sync(); cin.clear();
            goto getCrypt;
        }
    }

    void Encrypt(string& data)
    {

        for (int i=0; i<data.size();i++)
        {
            int offset=i;
            if (offset>5)
            {
                while (offset>5)
                {
                    offset-=6;
                }
            }
            float base = 2.0f;
            int testbit=pow(base,offset);//gets bit to test. Ex: if offset= 1 (2^1=2=binary 10) test bit is the 2nd least significant bit

            if (data[i]!=(data[i]^testbit)) //if testbit is 1 (tested using xOR)  
                {
                    data[i]= data[i]^Crypt[2];  //-> encrypt using  xOR Crypt[2]

                    testbit=pow(base,offset+2);

                    if(data[i]!=data[i]^testbit)// then if testbit is 1 (tested using xOR)  
                    {
                        data[i]=(data[i]^Crypt[0])+Crypt[3]; //-> encrypt using  xOR Crypt[0] then adding crypt[3]
                    }
                    else
                    {
                        data[i]=(data[i]^Crypt[1])+Crypt[1];//-> encrypt using  xOR Crypt[1] then adding crypt[1]
                    }
                }
            else
            {
                data[i]=((data[i]^Crypt[3])^Crypt[0])+Crypt[2];//-> encrypt using  xOR Crypt[1] then xOR Crypt[0] and finally adding crypt[1]
            }
        }
        return;
    }
};  

and main.cpp

#include "Alghorithm.h"
int main()
{
    string data="This sentence is going to be encrypted";
    Crypter Crypter;
    cout<<"\nEncrypting...";
    Crypter.Encrypt(data);
    cout<<"\n\nEncryption Successful\n\nEncrypted string: "<<data<<endl;
    cin.sync(); cin.clear();
}

Now you programming experts must be thinking how clumsy my algorithm is
and that most parts don’t even make sense for a encryption algorithm(which is possible)
but pretend it’s a nice algorithm that makes total sense.

This is the problem:

It compiles. It runs. It encryptes the sentence and prints the encrypted
version. But right before the program ends (in the screenshots you can see i forgot
to return a value in main, but I’ve fixed that and the problem is did not change a bit) a message pops
up(while running through the compiler) in debug mode [Check Screenshots] and 3 in release mode;

Most of them warn about an error caused by a corruption in the stack around Crypter ‘variable’.

I’m not even close to be considered an experienced programmer so I came here asking for your help.

Since the error only pops up when the program is ending does it mean it is a problem with the cleanup?

I’m totaly lost here. Any responses are appreciated.

NOTE: I’ve also included part of the assembly code (the relevant part) provided by te debugger;
Hope it has some use (check my inline comment on the asm code for the ‘position’ of the error);

Criticise my crappy code at will :)( It seems to have a problem since the resultant encrypted string differes from debug to release mode ?:/?.

-João

Screens:

How the program looks like before i press ENTER(Debug): http://i44.tinypic.com/3ert2.png

How the program looks like before i press ENTER(Release) http://i42.tinypic.com/2nld45f.png

Error shown after pressing ENTER (Debug) http://i41.tinypic.com/bhltoy.png

1st Error shown after pressing ENTER (Release) http://i42.tinypic.com/28lchac.png

2nd Error shown after pressing ENTER (Release) http://i40.tinypic.com/2h3ttmw.png

3rd Error shown after pressing ENTER (Release) http://i41.tinypic.com/2lc5suw.png

ASM Code provided by the debbuger http://pastebin.com/TTXUn0T2

  • 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-30T05:55:40+00:00Added an answer on May 30, 2026 at 5:55 am

    At least one error: you need to reserve 5 characters for the Crypt variable: you need the additional space to null-terminate the string.

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

Sidebar

Related Questions

EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Edit : SOLVED Right. I found the thing that confused me. I use pgadmin
EDIT: Solved My problem is that I need to find a way to constantly
Edit: I have solved this by myself. See my answer below I have set
EDIT: Solved. I was unware that enabling a language extension in the source file
EDIT: Solved the problem, thanks to this forum post: http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407 . Thanks everyone! I've
EDIT: SOLVED I'm working on a multi-threaded project right now where I have a
EDIT: SOLVED I encountered a problem while attempting to render into a texture. I
EDIT: solved. ans var needed to be set to 0 in every iteration.That was
EDIT: solved see comments --don't know how to mark as solved with out an

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.