-
Encryption
I seen another post on here about encryption and I thought I would try my hand at some XOR stuff. I had it perfect but know I want to add in the chance for people to write in the txt they want to be encrypted. I had that working but afterit decrypted the txt there was still a bunch of mubly jumbly after it. So I decided I wanted to clean it up. This is what I got. The comments explain where the errors are at and what they are.
Code:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
int main()
{ char a[501];
char b[502]="dmj7HaL(*EjJNuh88iNU67Jbn76n75hu767Bhg567b765mdsd4s";
char c[501];
int leg;
int g=0,h=0;
cout<<"\nPlease Input Some Text To Be Encrypted\n\n";
cin.getline(a,502);
strlen(a)=leg;//problem here I want "leg" to equal the length of "a" "non-lvalue in assignment error"
while(g<leg)
{
for(int x=0, x<502, x++)//parse error before")" here
{
c[x]=b[x]^a[x];
cout<<c[x];} //parse error before "}" here
g++;
}
cout<<"\n\nYour Decrypted Text\n\n"; }
while(h<leg)
{
for(int x=0, x<502, x++) //parse error before ")" here
{
a[x]=b[x]^c[x];
cout<<a[x];
} //parse error before "}" here
h++;
}
cout<<"\n\n";
system("PAUSE");
return 0;
} //parse error at the end of input here. There is also a "no8" error on line 14 of a source I don't have open call'd ß
-
that should be "leg = strlen(a);" and i believe that will fix all your other errors
-
Good news! Your loop parse errors are syntax errors. Take a
closer look. You also have a premature end main brace (}).
I'll let you find it.
hth,
-
But???
I know that they were syntax errors but I am not good enuff at reconizing them yet thats why I asked about them. I have only been programing for less the 3 weeks?
-
the commas in your for loops should be semicolons. Compare your code to this:
Code:
int main()
{
char a[53] = "\0"; // input
char b[] = " JNuh88iNU67Jbn76n75hu767Bhg567b765mdsd4s";
char c[53] = "\0"; // output
int leg, g = 0, h = 0;
cout << "\nPlease Input Some Text To Be Encrypted"
<< endl;
cin.getline( a, 52 );
leg = strlen( a );
cout << endl << "Your encrypted text: ";
for(int x = 0; x < leg; x++)
c[x] = b[x] ^ a[x]; // xor a to c
cout << c << endl; // you can treat an array as a string
cout << "\n\nYour Decrypted Text: ";
for( x = 0; x < leg; x++ )
{
a[x] = b[x] ^ c[x];
cout << a[x];
}
cout << "\n" << endl;
return 0;
}
hth,