Hi, this is the brute-force decrypt function I wrote, but it's not really working properly. I just need to find sub-expressions and then the key i is returned, so professor said to find most commonly used English words so I decided to use top 30 (from wikipedia). Is my use of the regular expression correct?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int bruteForceDecrypt(constchar *ciphertext, char *message, constint messageLength) {
boost::regex re(" the | be | to | of | and | a | in | that | have | I | it | for | not | on | with | he | as | you | do | at | this | but | his | by | from | they | we | say | her | she ");
for ( int i = 0; i < 65536; i++ )//to go through all the possible keys
{
crypt(i,ciphertext,message,messageLength);//decrypt the cipher text first
if (boost::regex_search(message ,re) == true)
return i;//return the key if you found a subexpression
}
return -1;
}