I am trying to write a program that takes in 2 string inputs and assigns a numeric value to each letter in the string input. The program then multiples the numeric values assigned to the letters in the string inputs and sees if the product of the values (mod 47) of both inputs are equal. If they are equal, then the program must output "yes" if not, then it must output "NO".
I am using a brute force method, so please feel free to suggest more efficient methods and also how to implement them. I have reached a point where my IDE only gives several warnings, but no errors. However when I run the program, I get an illegal instruction, which is essentially because of a particular function, which I will show later.
I WOULD PREFER THAT THE SOLUTIONS TO MY QUESTION DON'T INCLUDE ANY EXTRA CLASS LIBRARIES AND FILES. THANK YOU ;)
I've tried using a brute force method e.g in this long function:
This takes in values from a function of return type int which assigns the numeric value to the 6 letter input, and returns them to a variable of return type bool, which finds and compares the final product of the two strings before returning a value of type bool. I've used the brute force method of comparing each individual letter of the string to a letter and assigning a value. I am quite sure that the first function isn't right, although I don't know how to fix it.
int parse(const char * x)
{
if (x == "A")
{
return 1;
}
if (x == "B")
{
return 2;
}
if (x == "C")
{
return 3;
}
if (x == "D")
{
return 4;
}
if (x == "E")
{
return 5;
}
if (x == "F")
{
return 6;
}
if (x == "G")
{
return 7;
}
if (x == "H")
{
return 8;
}
if (x == "I")
{
return 9;
}
if (x == "J")
{
return 10;
}
if (x == "K")
{
return 11;
}
if (x == "L")
{
return 12;
}
if (x == "M")
{
return 13;
}
if (x == "N")
{
return 14;
}
if (x == "O")
{
return 15;
}
if (x == "P")
{
return 16;
}
if (x == "Q")
{
return 17;
}
if (x == "R")
{
return 18;
}
if (x == "S")
{
return 19;
}
if (x == "T")
{
return 20;
}
if (x == "U")
{
return 21;
}
if (x == "V")
{
return 22;
}
if (x == "W")
{
return 23;
}
if (x == "X")
{
return 24;
}
if (x == "Y")
{
return 25;
}
if (x == "Z")
{
return 26;
}
}
bool returnfunc(std::string & GROUP, std::string & k)
{
const char A = GROUP[0];
const char B = GROUP[1];
const char C = GROUP[2];
const char D = GROUP[3];
const char E = GROUP[4];
const char F = GROUP[5];
int xet = parse(&A);
int r = parse(&B);
int m = parse(&C);
int z = parse(&D);
int h = parse(&E);
int j = parse(&F);
double mu = (xet * r * m * z * h * j) % 47;
const char G = k[0];
const char H = k[1];
const char I = k[2];
const char J = k[3];
const char K = k[4];
const char L = k[5];
int w = parse(&G);
int x = parse(&H);
int y = parse(&I);
int a = parse(&J);
int b = parse(&K);
int c = parse(&L);
double fin = (w * x * y * a * b * c) % 47;
{
if (mu == fin)
{
return true;
}
else
{
return false;
}
}
}
/*I expected the program to run but it didn't and I don't understand
why.*/