Macbeth
First Post
For a project in my CS class, I have created the following code to create a binary tree, and use that tree to encrypt information, using the scheme:
0 - move one node left
1 - move one node right
2 - take the information from the current node.
Now I know that the code probably has all kinds of logic errors, but at this point it won't compile! I get a "PCH creation point" error every time. in the past this has usually been becuase I missed a semicolon, but damn if I know where that is. So I'm asking for somebody to pleas tell me where this error is coming from! I'll fix the (likely plentifil) logic errors on my own, i just want to know why the damn thing won't compile:
CryptoTree.h:
cryptoTest.cpp:
I know the lack of commenting is horrible, I was goign to comment it once I had working code. I'll try commenting it now, and post an easier to read version in a while, if nobody can read the code as is.
0 - move one node left
1 - move one node right
2 - take the information from the current node.
Now I know that the code probably has all kinds of logic errors, but at this point it won't compile! I get a "PCH creation point" error every time. in the past this has usually been becuase I missed a semicolon, but damn if I know where that is. So I'm asking for somebody to pleas tell me where this error is coming from! I'll fix the (likely plentifil) logic errors on my own, i just want to know why the damn thing won't compile:
CryptoTree.h:
Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;
class Node {
public:
char data;
Node *left;
Node *right;
Node (char inp) {
data = inp;
left = NULL;
right = NULL;
}
};
/*//////////////////////////////*/
class CryptoTree {
protected:
Node *head;
Node *nodeSearch (char info) {
Node *temp = head;
Node *decide = head;
while (decide != NULL) {
temp = decide;
if (info < temp->data) {
decide = decide->left;
} else {
decide = decide->right;
}
}
int search (Node *position, char info) {
if (position != NULL) {
if (search (position->left, info) == 1 || position->data == info || search (position->right, info) == 1){
return(1);
}
}
return(0);
}
string outSearch(Node *pos, char info, string out) {
string leftstring = out + "0";
string rightstring = out + "1";
if ( pos != NULL ){
if(pos->data == info){
return(out);
} else {
out = outSearch(pos->left, info, leftstring);
out = outSearch(pos->right, info, rightstring);
}
}
return(out);
}
int treeFull(){
int i;
for ( i = 48; i < 91; i++) {
if( search(head, ((char)i)) == 0){
return(0);
}
}
return(1);
}
void keyPrint(Node *target, string code) {
string leftcode = code + "0";
string rightcode = code + "1";
if(target->left != NULL){
keyPrint(target->left, leftcode);
}
cout << code << "2 - " << target->data << endl;
if(target->right != NULL){
keyPrint(target->right, rightcode);
}
return;
}
public:
CryptoTree () {
srand(static_cast<unsigned>(time(0)));
char rand;
int irand;
while(treeFull == 0){
irand = (48 + ((int) 43 * rand() / (RAND_MAX + 1.0)));
rand = (char)irand;
insert(rand);
}
} // constructor
void insert (char inp) {
Node *temp = new Node (inp);
if (head == NULL) {
head = temp;
} else {
Node *seek = nodeSearch (temp->data);
if (temp->data < seek->data) {
seek->left = temp;
} else {
seek->right = temp;
}
}
return;
} // insert
void returnKey(){
string init;
init = " ";
cout << "Encryption Key:" << endl;
printKey(head, init);
return;
}
string encrypt(string input){
char targ;
string starter = "";
int max = input.length();
int j;
for( j = 0; j < max; j++){
targ = input[j];
starter = starter + outSearch(head, targ, starter);
}
return(starter);
}
string decrypt(string input){
int max;
int k;
node *trav;
string out;
trav = head;
max = input.length();
out = "";
for(k = 0; k < max; k++){
if(input[k] == 2){
out = out + (trav->data);
}else if(input[k] == 0){
trav = trav->left;
}else{
trav = trav->right;
}
}
return(out);
}
};
cryptoTest.cpp:
Code:
#include "Crypto.h"
int main() {
CryptoTree Trial;
Trial.returnKey();
return(0);
}
I know the lack of commenting is horrible, I was goign to comment it once I had working code. I'll try commenting it now, and post an easier to read version in a while, if nobody can read the code as is.