PDA

View Full Version : My Encrypt program help



Moonbat
09-21-2006, 06:48 PM
This is a simple encrypter program I made in C++. It takes 6 single digits, and converts them to their 'char' equivelent (ASCII I think.) So if you type 6 as a digit, it would convert it to the char equivelent, which is a spade sign. I know its not much, but I seem to have problems. Here is the code. I'd appreciate it if someone helped me out. (BTW, the wait4user function isn't mine, someone else had it in their code, and i copy/pasted it)

#include <iostream>
#include <string.h>
using namespace std;
void wait4user();
int main()
{
cout << "Please enter 6 digit password, and press enter after each digit\n";
int psword[6];
cin >> psword[*];
cin >> psword[2];
cin >> psword[*];
cin >> psword[4];
cin >> psword[5];
cin >> psword[6];
cout << "\n\aEncryption will now begin\n";
char p[6];
p[*]=psword[*]+*;
p[2]=psword[2]+*;
p[*]=psword[*]+5;
p[4]=psword[4]+7;
p[5]=psword[5]+*;
p[6]=psword[6]+**;
cout << "Here is your new password!\n";
cout << p[*];
cout << " ";
cout << p[2];
cout << " ";
cout << p[*];
cout << " ";
cout << p[4];
cout << " ";
cout << p[5];
cout << " ";
cout << p[6];
cout << " \n";
cout << "Press Enter to terminate program...";
wait4user();

return 0;
}

void wait4user()
{
std::string response;
std::cout << "Press Enter to continue";
std::getline(std::cin, response);
}

Everytime i run it, it gets to the line saying "Encryption will now begin" but suddenly terminates.

SyntaXmasteR
09-22-2006, 01:01 PM
DO NOT COPY AND PASTE CODE!! :rolleyes:

I'm not a big C++ coder, I found a few potential problems with your code (depending on your compiler):


#include <iostream>

Some compilers are looking for the .h extension and will give an error #include <iostream.h>

You also created some very odd arrays:


psword[6]
p[6]


The 6 means each array is has a maximun of 6 characters but you try to manually assigned a value into the 7th position of the array. The first array value starts at position 0 not *:


psword[0]
p[0]


Its hard to critique code when its not your language but this would be the easiest way for you to perform the same task. This might not be the correct syntax for C++ but this is how I would rewrite the code:



#include <iostream>
#include <string.h>
using namespace std;
void wait4user();
int main()
{
string psword[6];
char p[6];


cout << "Please enter 6 digit password, and press enter after each digit\n";
cin >> psword;

cout << "\n\aEncryption will now begin\n";

int salt=*
for(i=0;i<psword.length();i++)
{
p[i]=int psword[i]+salt;
salt=salt+2;
}
cout << "Here is your new password!\n";
cout << p;

cout << " \n";
cout << "Press Enter to terminate program...";
wait4user();

return 0;
}

void wait4user()
{
std::string response;
std::cout << "Press Enter to continue";
std::getline(std::cin, response);
}

Moonbat
09-22-2006, 04:53 PM
Why shouldn't I copy and paste code? How are you gonna see it?

SyntaXmasteR
09-22-2006, 05:11 PM
Copy and Pasters make lots of mistakes.

Did you try the script?

Moonbat
09-22-2006, 05:26 PM
Yeah, I had to make a couple tweaks.
Right now, I'm working on making it so whatever number you type will be turned into a random letter, because it'll be hard to make a decrypter for symbols like spades and diamonds.

SyntaXmasteR
09-22-2006, 05:29 PM
You need to write a formula before you encrypt your text. Then you reverse that formula for decryption. You write the code after you create the formulas.

Ezekiel
09-23-2006, 04:03 AM
Why shouldn't I copy and paste code? How are you gonna see it?

He doesn't mean you shouldn't copy and paste code here, he means you shouldn't copy and paste other people's code into your own program. It's always best to type out code yourself so you learn from it and also see any errors it has.

Moonbat
09-23-2006, 12:03 PM
Oh okay, I'm just about to finish it, then i can post it up

Moonbat
09-23-2006, 01:27 PM
Here is the end result of my work (Now I'm gonna try to go backwards)
The program asks for 6 digits 0-* for a password, then converts them to to ASCII letters, by adding 65 to their value. Here it is.


//Number to ASCII Letter Convertion Program: By Moonbat
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
void wait4user();
int main()
{
int psword[6]; //creating array for password
char p[6]; //creating array for new password
int i; //counter for Second Loop
int d; //counter for First Loop

cout << "Please enter 6 numbers 0-* for a password, and press enter after each number\n";
cin >> psword[0]; //taking values for old password
cin >> psword[*];
cin >> psword[2];
cin >> psword[*];
cin >> psword[4];
cin >> psword[5];

cout << "\n\aEncryption will now begin.\n";
wait4user();//function to force user to press Enter

for (d=0;d<65;d++)//loop, whcih will make all psword values
{ //in the ASCII alphabet range
psword[0]++;
psword[*]++;
psword[2]++;
psword[*]++;
psword[4]++;
psword[5]++;
}

for(i=0;i<6;i++)//loop to convert old password to new password
{
p[i]= psword[i];
}
cout << "\nHere is your new password!\n";
cout << p[0];
cout << p[*];
cout << p[2];
cout << p[*];
cout << p[4];
cout << p[5];
cout << "\n";
wait4user();

return *;
}

void wait4user()//function-NOT MINE, someone else's function
{
std::string response;
std::cout << "Press Enter to continue";
std::getline(std::cin, response);
}