- Code: Select all
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
//Variables
string tstr, pstr;
char tcha[1000], pcha[20], answer;
int key, aspch, num1, num2, num3, i, intarray[1000];
bool running=true;
//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)
{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()
{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;
for (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);}
and here are the errors I get when compiling:
- Code: Select all
xecryption.cpp: In function ‘void charfunc(char, int)’:
xecryption.cpp:24: error: invalid types ‘char[int]’ for array subscript
xecryption.cpp:25: error: invalid types ‘char[int]’ for array subscript
xecryption.cpp: In function ‘int main()’:
xecryption.cpp:41: error: invalid conversion from ‘char*’ to ‘char’
xecryption.cpp:41: error: initializing argument 1 of ‘void charfunc(char, int)’
I have fixed other errors before, but I don't really get what these ones mean...
Thanks for helping!



