Hate to say it, but this function is not correct. Right at the start of the function is a test for the number of words in the string (i.e. is it a password or passphrase). If a space is found in the string, then it is assumed that the string consists of a number of Diceware words. This assumption cannot be made. Let the program compare between the password 'Tr0ub4dor&3' and the passphrase 'Tr0ub4dor&3 Tr0ub4dor&3'. It will tell you the latter is the weakest, which it is clearly not. Not every string containing spaces is a list of Diceware words. It should at least be tested if the words are alphanumeric (without special characters). So there are two things to improve: (1) decide if the words are 'plain' words, not containing any ampersands etc., and (2) decide if they are indeed from the limited Diceware word list that contains a mere 7776 words.