- Code: Select all
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
//Randomizing function:
signed int rmz(void)
{srand((unsigned)time(0));
int random;
int lowest= -10, highest= 10;
int range= (highest-lowest)+1;
random = lowest + int(range*rand() /(RAND_MAX + 1.0));
return random;}
//Encrypting function:
void charfunc (char tcha[], int key)
{int num1, num2, num3, i, intarray[1000];
for (i=0; tcha[i] != '\0'; i++)
{intarray[i]=(int)tcha[i];
num1=((intarray[i]+key)/3)+rmz();
num2=((intarray[i]+key)/3)+rmz();
num3=((num1+num2)-intarray[i])+key;
cout << '.' << num1 << '.' << num2 << '.' << num3;}}
int main()
{char tcha[1000], pcha[20], answer;
int key, aspch;
bool running=true;
do
{ cout << "Type or paste some text to encrypt (under 1000 characters): " << endl;
cin >> tcha;
cout << endl << "Now enter the password (under 20 characters): ";
cin >> pcha;
//Making the password into a number (key):
for (int i=0; pcha[i] != '\0'; i++)
{aspch=(int)pcha[i];
key+=aspch;}
charfunc(tcha, key);
cout << endl << endl << "Encrypt more text? [y/n] ";
cin >> answer;
if (answer=='y')
break;
else
{return 0;
running=false;}}
while (running==true);}
So as I said, this compiles fine and I was really pleased! BUT... it doesn't work right. D: When I run it here's what happens (my input is in bold, comments in italics):
Type or paste some text to encrypt (under 1000 characters):
hello this is a test
Now enter the password (under 20 characters): <--Not waiting for a response here .-402823458.-402823458.-2014117468.-402823459.-402823459.-2014117467.-402823456.-402823456.-2014117468.-402823456.-402823456.-2014117468.-402823455.-402823455.-2014117469
Encrypt more text? [y/n] <--Once again not waiting for my response, it just ends the program!


