Okay so lately I have been messing around with encryption. I thought I might give making my own simple encryption program a shot. So I am trying to make it. I am compiling my code in DEV C++ and when it runs, after I enter the message, nothing happens. It stops working. I get no text output, and I cant exit out unless I click the red X or CTRL-c. Can someone take a look and see what I am doing wrong. Help would be greatly appreciated.

If any other details are needs I will be gladly to supply them.

#include <iostream>

using namespace std;

char key[4];
char charcrypt[4];
char msg[2];
char cryptmsg[2];
int asciikey[4];
int currentchar[2];
int asciicharcrypt[4];
int i = 0;


int main(){
    cout << "Key: ";
    cin >> key;
    cout << "Message: ";
    cin >> msg;
    
    asciikey[0] = int(key[0]);
    asciikey[1] = int(key[1]);
    asciikey[2] = int(key[2]);
    
    while( i < 1 )
    {
       currentchar[0] = int(msg[i]);
       asciicharcrypt[0] = currentchar[0] + asciikey[0] - asciikey[1] + asciikey[2] % 255;
       asciicharcrypt[1] = currentchar[0] + asciikey[0] - asciikey[1] + asciikey[2] % 255;
       asciicharcrypt[2] = currentchar[0] + asciikey[0] - asciikey[1] + asciikey[2] % 255;
    
       charcrypt[0] = char(asciicharcrypt[0]);
       charcrypt[1] = char(asciicharcrypt[1]);
       charcrypt[2] = char(asciicharcrypt[2]);
       
       cryptmsg[i] = charcrypt[1,2,3,4];
    }
    
    cout << endl << endl << cryptmsg[0] << endl;
    cin.get();
    cin.get();
    return 0;
}

i never changes within your while loop on line 25, so you're always stuck at 0 < 1 and it loops forever.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.