Making a program that encodes text, "Process returned -1073741819 (0xC0000005)" console

-3

I'm currently coding a program that encodes text using the Vigenere cipher. I've done everything I could to research this question and I'm sure I'm doing everything correctly, however I receive a "Process returned -1073741819" in the console. Here is my code:

#include <iostream>
#include <string>
#include <locale>
using namespace std;

int main()
{
char table[25][25] = {{'A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'},
                    {'B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A'},
                    {'C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B'},
                    {'D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C'},
                    {'E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D'},
                    {'F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E'},
                    {'G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F'},
                    {'H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G'},
                    {'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H'},
                    {'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J'},
                    {'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K'},
                    {'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L'},
                    {'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M'},
                    {'O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N'},
                    {'P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O'},
                    {'Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P'},
                    {'R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q'},
                    {'S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R'},
                    {'T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S'},
                    {'U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T'},
                    {'V','W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U'},
                    {'W','X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V'},
                    {'X','Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'},
                    {'Y','Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X'},
                    {'Z','A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y'}};

string keyword;
string realkey;
string message;
string decryption;
unsigned int keyI = 0;
cout << "What is your keyword to decode with?\n";
getline(cin, keyword);

for(unsigned int i = 0; i<keyword.length(); i++){
    if(keyword.at(i) != ' '){
        realkey.append(keyword,i,1);
    }
}
for(unsigned int i = 0; i<realkey.length(); i++){
    if(realkey.at(i) >= 97 && realkey.at(i) <=122){
        realkey.at(i) -= 32;
    }
}
cout << "What is the message you want to encrypt?\n";
getline(cin, message);
for(unsigned int i = 0; i<message.length(); i++){
    if(message.at(i) >= 97 && message.at(i) <=122){
        message.at(i) -= 32;
    }
}
decryption = message; // just to make the two strings have the same length
for(unsigned int i = 0; i<message.length(); i++){
    if(message.at(i) != ' '){
        decryption.at(i) = table[realkey.at(keyI)][message.at(i)-65]; // A=0, B=1
    }
    if(keyI < realkey.length()){
        keyI++;
    }
    else{
        keyI = 0;
    }
}
cout << decryption << endl;

}

If you don't understand the Vigenere cipher, unfortunately you'll have to search that up since I can't really explain it without confusing anyone.

I'm certain my error lies here, since my program works correctly until it comes to this portion of the code:

    for(unsigned int i = 0; i<message.length(); i++){
    if(message.at(i) != ' '){
        decryption.at(i) = table[realkey.at(keyI)][message.at(i)-65]; // A=0, B=1
    }
    if(keyI < realkey.length()){
        keyI++;
    }
    else{
        keyI = 0;
    }
}
cout << decryption << endl;

First, I ask for a keyword, and that works. Then, I ask for the message, and that works as well. Then, the loading-circle gets displayed on the screen next to my cursor and I receive the Process returned -1073741819 in the console. I know it doesn't work since it doesn't print out the decryption.

If you need any more information about the program or any information that will help you help me, please ask.

EDIT: This is what I see in the console:

What is your keyword to decode with?
mykey
What is the message you want to encrypt?
message

Process returned -1073741819 (0xC0000005)   execution time : 12.040 s
Press any key to continue.

EDIT2: This is what I see in the debugger:

Active debugger config: GDB/CDB debugger:Default Building to ensure sources are up-to-date Selecting target: Debug Adding source dir: C:\Projects\proj28\ Adding source dir: C:\Projects\proj28\ Adding file: C:\Projects\proj28\bin\Debug\proj28.exe Changing directory to: "C:\Projects\proj28\." Set variable: PATH=.;C:\Codeblocks\MinGW\bin;C:\Codeblocks\MinGW;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Jag\AppData\Local\Microsoft\WindowsApps Starting debugger: C:\Codeblocks\MinGW\bin\gdb-5.2.1-1.exe -nx -fullname -quiet -args "C:\Projects\proj28\bin/Debug/proj28exe" failed

c++
encryption
console
vigenere
asked on Stack Overflow Dec 2, 2018 by A. Kim • edited Dec 2, 2018 by A. Kim

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0