static void Main(string[] args) { Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"); //The folliwng is the trying of the spell checking Console.WriteLine("Trying Spell Checking for the word 'Recommendation'"); Console.WriteLine(hunspell.Spell("Recommendation")); //The following is the trying of the suggesstions Console.WriteLine("\n\n"); Console.WriteLine("Trying the suggesstions of the word 'Recommnedatio'"); List<string> suggesstions = new List<string>(); suggesstions = hunspell.Suggest("Recommnedatio"); foreach (string item in suggesstions) { Console.WriteLine(" --" + item); } //The following is the trying of analysis of word Console.WriteLine("\n\n"); Console.WriteLine("Analyze the word 'children'"); List<string> morphs = hunspell.Analyze("children"); foreach (string morph in morphs) { Console.WriteLine("Morph is: " + morph); } //The following is the trying of Stemming Console.WriteLine("\n\n"); Console.WriteLine("Find the word stem of the word 'children'"); List<string> stems = hunspell.Stem("children"); foreach (string stem in stems) { Console.WriteLine("Word Stem is: " + stem); } //Now for the synonym functions Console.WriteLine("\n\n\nThesaurus/Synonym Functions"); Console.WriteLine("¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"); //Creating a new instance of the thesarus MyThes thes = new MyThes("th_en_us_v2.dat"); //Synonyms for words Console.WriteLine("Get the synonyms of the plural word 'children'"); ThesResult tr = thes.Lookup("how", hunspell); if (tr.IsGenerated) Console.WriteLine("Generated over stem (The original word form wasn't in the thesaurus)"); foreach (ThesMeaning meaning in tr.Meanings) { Console.WriteLine(); Console.WriteLine(" Meaning: " + meaning.Description); foreach (string synonym in meaning.Synonyms) { Console.WriteLine(" Synonym: " + synonym); } } }
protected override void OnKeyDown(KeyEventArgs e) { DirectoryInfo d = new DirectoryInfo("."); string d2 = d.FullName; if (e.KeyCode == Keys.Up && e.Alt) { using (Hunspell hunspell = new Hunspell(DictLanguage + ".aff", DictLanguage + ".dic")) { Dictionary<string, string> Replacements = new Dictionary<string, string>(); // string[] split = Text.Split(new char[] { ' ', '!', '?', '.', ',', ':', ';', '\n', '\r', '(', ')', '-', '=' }, StringSplitOptions.RemoveEmptyEntries); // foreach (string word in split) var mts = Regex.Matches(Text, "\\b\\w*\\b"); for (int i = 0; i < mts.Count; i++) { string word = mts[i].Value; if (Replacements.ContainsKey(word) || ignoreText.Contains(word)) continue; bool correct = hunspell.Spell(word); if (!correct) { frmSpeller sp = new frmSpeller(word, hunspell); sp.ShowDialog(); if (sp.ResultAction == frmSpeller.Action.Stop) break; if (sp.ResultAction == frmSpeller.Action.keep) { if (!ignoreText.Contains(word)) ignoreText.Add(word); } else { Replacements.Add(word, sp.ResultString); } } } string outv = this.Text; foreach (var item in Replacements.Keys) { outv = Regex.Replace(outv, "\\b" + item + "\\b", Replacements[item]); } this.Text = outv; //Console.WriteLine("Make suggestions for the word 'Recommendatio'"); //List<string> suggestions = hunspell.Suggest("Recommendatio"); //Console.WriteLine("There are " + suggestions.Count.ToString() + " suggestions"); //foreach (string suggestion in suggestions) //{ // Console.WriteLine("Suggestion is: " + suggestion); //} } } base.OnKeyDown(e); }
/// <summary> /// Spell check the specified word. /// </summary> /// <param name="word"> /// The word. /// </param> /// <returns> /// true if word is correct, otherwise false. /// </returns> public bool Spell(string word) { Hunspell hunspell = this.HunspellsPop(); try { return(hunspell.Spell(word)); } finally { this.HunspellsPush(hunspell); } }
internal string CheckEnglishSpelling() { bool correct; List<string> suggestions = new List<string>(); //Generate XML for the AtD plugin to read. StringWriter stringwriter = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; XmlWriter xmlWriter = XmlWriter.Create(stringwriter, settings); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("results"); string lastWord = string.Empty; //We create hunspell object and pass the location of the english dictionary. using (Hunspell hunspell = new Hunspell(System.Web.HttpContext.Current.Server.MapPath("~/Content/Dictionaries/en_US.aff"), System.Web.HttpContext.Current.Server.MapPath("~/Content/Dictionaries/en_US.dic"))) { //Split the paragraph to words List<string> words = Regex.Split(EnglishSynopsis, @"\W+").ToList(); foreach (string word in words) { //Check the spelling and returns true or false correct = hunspell.Spell(word); if (!correct) { xmlWriter.WriteStartElement("error"); xmlWriter.WriteElementString("string", word); xmlWriter.WriteElementString("description", "Spelling"); xmlWriter.WriteElementString("precontext", lastWord); xmlWriter.WriteStartElement("suggestions"); //Returns list of suggestion for the incorrect word suggestions = hunspell.Suggest(word); foreach (string suggestion in suggestions) { xmlWriter.WriteElementString("option", suggestion); } xmlWriter.WriteEndElement(); xmlWriter.WriteElementString("type", "spelling"); xmlWriter.WriteEndElement(); } lastWord = word; } } xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); return stringwriter.ToString(); }
public static int CheckSpelling(string body) { int errors = 0; string[] contents = body.Split(' '); using (Hunspell spell = new Hunspell()) { foreach (var item in contents) { if (!(spell.Spell(item))) { errors++; } } } return errors; }
/// <summary> /// Checks the spelling of the specified text /// </summary> /// <param name="affFile">The affFile path</param> /// <param name="dicFile">The dictionary file path</param> /// <param name="text">The text to spell check</param> /// <returns></returns> public static string CheckSpelling(string affFile, string dicFile, string text) { bool success = true; List<string> misspelledWords = new List<string>(); List<List<string>> data = new List<List<string>>(); try { using (Hunspell hunspell = new Hunspell(affFile, dicFile)) { var words = text.Split((char[])null); //check the spelling of each word foreach (var word in words) { if (!hunspell.Spell(word)) misspelledWords.Add(word); } data.Add(misspelledWords); } } catch (Exception exception) { //need to add logging success = false; } var results = new SpellCheckResults { Outcome = success ? "success" : "error", Data = success ? data : null }; return JsonConvert.SerializeObject(results); }
public bool IsValidWord(string word) { return(hunspell.Spell(word)); }
/// <summary> /// It evaluates the responses provided by the student with the responses given by a instructor to grade a test using two separate XMLs. /// MCQs and Fill in the blanks type of questions are graded by comparing the responses, while Essay question is graded based on the /// number of keywords or their synonyms used, grammatical errors, spellcheck, word limit and paragraphs. /// </summary> private void CalculateMarks() { XmlSerializer ser = new XmlSerializer(typeof(Test)); finalTest = ser.Deserialize(new FileStream("D:\\test.xml", FileMode.Open)) as Test; totalQuestions = test.Question.Count(); ser = new XmlSerializer(typeof(TestAnswers)); finalTestAnswer = ser.Deserialize(new FileStream("D:\\StudentResponse.xml", FileMode.Open)) as TestAnswers; List<TestQuestion> quesList = new List<TestQuestion>(); for (int i = 0; i < totalQuestions; i++) { quesList.Add(finalTest.Question[i]); } int j = 0; double essayMarks = 100.0f; foreach (var question in quesList) { if (question.Type == QuesTypeVal.MCQ.ToString()) { if (question.Option1.Answer == "Yes" && question.Option1.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } else if (question.Option2.Answer == "Yes" && question.Option2.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } else if (question.Option3.Answer == "Yes" && question.Option3.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } else if (question.Option4.Answer == "Yes" && question.Option4.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } j++; } else if (question.Type == QuesTypeVal.Text.ToString()) { if (question.Answer.Text == finalTestAnswer.Answer[j].Value) { marks += 5; } j++; } else if (question.Type == QuesTypeVal.EssayText.ToString()) { string essayResponse = finalTestAnswer.Answer[j].Value; int nKeyword = question.Answer.Keyword.Count(); double keywordMark = 40.0 / (double)nKeyword; int checkSynonym = 0; double wordMarks = 0.0f; List<string> essayList = new List<string>(); var essayString = Regex.Split(essayResponse, @"[\n]+"); int noParagraphs = essayString.Count(); bool nParaCorrect = false; for (int i = 0; i < noParagraphs; i++) { if (essayString[i] != string.Empty) essayList.Add(essayString[i]); } if (essayList.Count() != question.NumberOfParagraphs) { essayMarks = 20; } else { List<string> wordList = new List<string>(); foreach (string essayPara in essayList) { var s = Regex.Split(essayPara, @"[,\s\n]+"); foreach (string k in s) { wordList.Add(k); } } if (wordList.Count >= question.TotalNumberOfWords) { essayMarks = 20; } else { bool grammarCheck = true; Microsoft.Office.Interop.Word.Application myWord = new Microsoft.Office.Interop.Word.Application(); foreach (string essay in essayList) { grammarCheck = myWord.CheckGrammar(essay); if (!grammarCheck) { essayMarks -= 5; } } wordMarks = 40.0 / (double)wordList.Count(); foreach (string word in wordList) { using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) { if (!hunspell.Spell(word)) { essayMarks -= wordMarks; } } } bool keyPresent = false; for (int i = 0; i < nKeyword; i++) { if (!essayResponse.Contains(question.Answer.Keyword[i])) { List<string> stringArr = new List<string>(); stringArr.Add(question.Answer.Keyword[i]); SynonymInfo theSynonyms = myWord.SynonymInfo[question.Answer.Keyword[i]]; foreach (var Meaning in theSynonyms.MeaningList as Array) { if (stringArr.Contains(Meaning) == false) stringArr.Add((string)Meaning); } for (int ii = 0; ii < stringArr.Count; ii++) { theSynonyms = myWord.SynonymInfo[stringArr[ii]]; foreach (string Meaning in theSynonyms.MeaningList as Array) { if (stringArr.Contains(Meaning)) continue; stringArr.Add(Meaning); } if (stringArr.Count >= 10) { stringArr.ToArray(); break; } } foreach (string key in stringArr) { if (essayResponse.Contains(key)) { keyPresent = true; } } if (!keyPresent) { essayMarks -= keywordMark; } } } } } } } marks += essayMarks; }
public void SetErrorCount(Hunspell hunspell) { int errorCount = 0; foreach(Match match in this.Matches) { if(hunspell.Spell(match.Value) == false) { errorCount += 1; } } this.m_ErrorCount = errorCount; }
static void Main(string[] args) { #region OpenFiles // get the file reader StreamReader reader; try { reader = new StreamReader(args[0]); } catch(Exception e) { Console.WriteLine("an error occurred while opening the file: " + e.Message); return; } // get the file writer if (!File.Exists(RESULT_FILE)) File.Create(RESULT_FILE); StreamWriter writer = new StreamWriter(RESULT_FILE); writer.WriteLine(DataFileManager.minitabFileHeader); #endregion Word word; int numWords = 0; HashSet<string> okWords = new HashSet<string>(); HashSet<string> ignoreWords = new HashSet<string>(); Console.WriteLine("Going through file...\n"); using (Hunspell checker = new Hunspell("en_us.aff", "en_us.dic")) { reader.ReadLine(); while (!reader.EndOfStream) { word = DataFileManager.MinitabFileLine(reader.ReadLine()); if (checker.Spell(word.ToString()) || okWords.Contains(word.ToString())) { writer.WriteLine(DataFileManager.MinitabFileLine(word)); } else if(!ignoreWords.Contains(word.ToString())) { ColorWrite("Word #: " + numWords, ConsoleColor.Green); Console.Write(word.Source + ": '" + word.ToString() + "'" + " was not recognized as a word. Do you want to keep it? (y/n): "); if (Console.ReadKey().Key == ConsoleKey.Y) { writer.WriteLine(DataFileManager.MinitabFileLine(word)); okWords.Add(word.ToString()); } else { Console.Write("\nDo you want to offer an alternate spelling? (y/n): "); if (Console.ReadKey().Key == ConsoleKey.Y) { Console.Write("\nspelling: "); string input = Console.ReadLine(); foreach(string s in Sampler.Tokenize(input)) { Word newWord = new Word(s, word.Source, word.SourceDate, word.Topic); writer.WriteLine(DataFileManager.MinitabFileLine(newWord)); okWords.Add(newWord.ToString()); } } else { ColorWrite("\nThe word will be ignored.", ConsoleColor.Red); ignoreWords.Add(word.ToString()); } } Console.WriteLine("\n"); } numWords++; } } // End the program ColorWrite(numWords + " words processed.", ConsoleColor.Green); reader.Close(); writer.Close(); }
private void CheckWords(Word.Document doc, Hunspell hunspell, string selectedText, string[] khmerwords, out bool stopcheck, out bool repeatcheck, string objecttype = "", object wordobject = null) { int startposition = 0; Object oMissing = System.Reflection.Missing.Value; stopcheck = repeatcheck = false; //Check all the Khmer words from the selected line foreach (string khmerword in khmerwords) { DialogResult dialogResult = DialogResult.None; frmKhmer frmKhmer = null; String newKhmerWord = String.Empty; if (!hunspell.Spell(khmerword)) { if (!ignoreAllWords.Any(ignoreAllWord => ignoreAllWord.khmerword == khmerword)) { if (!ignoreWords.Contains(new IgnoreWord { document = doc.Name, khmerword = khmerword, selectedText = selectedText, startposition = startposition, ignoreAll = false })) { Word.Range start = null; Word.WdColorIndex highlightcolorindex = Word.WdColorIndex.wdNoHighlight; Word.WdUnderline fontunderline = Word.WdUnderline.wdUnderlineNone; Word.WdColor fontcolor = Word.WdColor.wdColorBlack; Word.Range selectionRange = null; //Select the erroneous word on the main document if (String.IsNullOrWhiteSpace(objecttype)) { //Set the initial selection start = doc.ActiveWindow.Selection.Range; //Set the search area doc.ActiveWindow.Selection.Start += startposition; Word.Selection searchArea = doc.ActiveWindow.Selection; //Set the find object Word.Find findObject = searchArea.Find; findObject.ClearFormatting(); findObject.Text = khmerword; //Find the mis-spelled word findObject.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); //Temp store the current formatting highlightcolorindex = doc.ActiveWindow.Selection.Range.HighlightColorIndex; fontunderline = doc.ActiveWindow.Selection.Range.Font.Underline; fontcolor = doc.ActiveWindow.Selection.Range.Font.UnderlineColor; //Highlight the selection doc.ActiveWindow.Selection.Range.HighlightColorIndex = Word.WdColorIndex.wdYellow; doc.ActiveWindow.Selection.Range.Font.Underline = Word.WdUnderline.wdUnderlineWavy; doc.ActiveWindow.Selection.Range.Font.UnderlineColor = Word.WdColor.wdColorRed; selectionRange = doc.ActiveWindow.Selection.Range; doc.ActiveWindow.Selection.Collapse(); } else { if (objecttype == "table") { start = ((Word.Cell)wordobject).Range; } else if (objecttype == "shape") { start = ((Word.Shape)wordobject).TextFrame.TextRange; start.Start += startposition; } //Set the find object Word.Find findObject = start.Find; findObject.ClearFormatting(); findObject.Text = khmerword; //Temp store the current formatting highlightcolorindex = start.HighlightColorIndex; fontunderline = start.Font.Underline; fontcolor = start.Font.UnderlineColor; //Find the mis-spelled word findObject.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); //Highlight the selection start.HighlightColorIndex = Word.WdColorIndex.wdYellow; start.Font.Underline = Word.WdUnderline.wdUnderlineWavy; start.Font.UnderlineColor = Word.WdColor.wdColorRed; start.Select(); } bool isObject = !String.IsNullOrWhiteSpace(objecttype); frmKhmer = new frmKhmer(selectedText, khmerword, startposition, hunspell.Suggest(khmerword), isObject); dialogResult = frmKhmer.ShowDialog(); //Select the line again if (String.IsNullOrWhiteSpace(objecttype)) { //Revert the highlights selectionRange.Select(); doc.ActiveWindow.Selection.Range.HighlightColorIndex = highlightcolorindex; doc.ActiveWindow.Selection.Range.Font.Underline = fontunderline; doc.ActiveWindow.Selection.Range.Font.UnderlineColor = fontcolor; if (dialogResult != DialogResult.Abort) start.Select(); } else { start.HighlightColorIndex = highlightcolorindex; start.Font.Underline = fontunderline; start.Font.UnderlineColor = fontcolor; if (dialogResult != DialogResult.Abort) { if (objecttype == "table") { ((Word.Cell)wordobject).Select(); } else if (objecttype == "shape") { ((Word.Shape)wordobject).Select(); } } } } } } #region Cancel Button Clicked //Return if the user hits Cancel Button if (dialogResult == DialogResult.Cancel || dialogResult == DialogResult.Abort) { stopcheck = true; repeatcheck = false; return; } #endregion #region Ignore or Ignore All Clicked //Ignore the word if (dialogResult == DialogResult.Ignore) { if (frmKhmer.ignoreAll) { ignoreAllWords.Add(new IgnoreWord { khmerword = khmerword, ignoreAll = frmKhmer.ignoreAll }); } else { ignoreWords.Add(new IgnoreWord { document = doc.Name, khmerword = khmerword, selectedText = selectedText, startposition = startposition }); } } #endregion #region Change or Change All Clicked if (dialogResult == DialogResult.Yes) { if (String.IsNullOrWhiteSpace(objecttype)) { //Set the initial selection Word.Range start = doc.ActiveWindow.Selection.Range; //Set the searcharea if (frmKhmer.changeAll) { doc.Content.Select(); } Word.Selection searchArea = doc.ActiveWindow.Selection; //Set the find object Word.Find findObject = searchArea.Find; findObject.ClearFormatting(); findObject.Text = khmerword; findObject.Replacement.ClearFormatting(); findObject.Replacement.Text = frmKhmer.selectedSuggestion; object replaceAll = frmKhmer.changeAll ? Word.WdReplace.wdReplaceAll : Word.WdReplace.wdReplaceOne; findObject.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing); newKhmerWord = frmKhmer.selectedSuggestion; //Set back the selection start.Select(); //Set repeatcheck to true if (frmKhmer.changeAll) { stopcheck = false; repeatcheck = true; return; } } else { var resultingText = selectedText.Replace(khmerword, frmKhmer.selectedSuggestion); if (objecttype == "table") { Word.Range range = ((Word.Cell)wordobject).Range; range.Text = resultingText; } else if (objecttype == "shape") { Word.Shape shape = (Word.Shape)wordobject; shape.TextFrame.TextRange.Text = resultingText; } stopcheck = false; repeatcheck = true; return; } } #endregion startposition += String.IsNullOrWhiteSpace(newKhmerWord) ? khmerword.Length : newKhmerWord.Length; } }
public Result GetSuggestions(string input) { string dictionaryPath = Hunspell.NativeDllPath; spellEngine = new SpellEngine(); LanguageConfig enConfig = new LanguageConfig(); enConfig.LanguageCode = "en"; enConfig.HunspellAffFile = Path.Combine(dictionaryPath, "en_us.aff"); enConfig.HunspellDictFile = Path.Combine(dictionaryPath, "en_us.dic"); enConfig.HunspellKey = ""; enConfig.HyphenDictFile = Path.Combine(dictionaryPath, "hyph_en_us.dic"); enConfig.MyThesDatFile = Path.Combine(dictionaryPath, "th_en_us_new.dat"); spellEngine.AddLanguage(enConfig); Result objResult = new Result(); bool correct1; using (var hunspell = new Hunspell(enConfig.HunspellAffFile, enConfig.HunspellDictFile)) { string[] lines = System.IO.File.ReadAllLines(@ConfigurationManager.AppSettings["FilePath"].ToString()); foreach (var line in lines) { hunspell.Add(line.ToLower()); } correct1 = hunspell.Spell(input.ToLower()); } bool correct = false; try { correct = SpellEngine["en"].Spell(input); if (correct = correct1 == false) { objResult.Suggestions = SpellEngine["en"].Suggest(input); objResult.State = "false"; } else { objResult.State = "true"; } } catch (Exception ex) { } return objResult; }
private static bool SpellCheck(string word) { bool result; using (var hunspell = new Hunspell(AffFilePath, DictionaryFilePath)) { result = hunspell.Spell(word); } return result; }
private bool checkSpelling(string clear) { bool retVal = false; string[] words = clear.Split(' '); int correct = 0; int incorrect = 0; if (clear.Trim().Length == 0) { retVal = false; } else if (words.Length < 10) { retVal = false; } else { using (Hunspell _hunspell = new Hunspell(_aff, _dic)) foreach (string word in words) { if (_hunspell.Spell(word)) correct++; else incorrect++; if (incorrect > words.Length / 2 || correct > words.Length / 2) break; } } if (correct > words.Length / 2) retVal = true; return retVal; }
public void DoSomething(object parameter) { //TO DO if (parameter is System.Windows.Controls.PasswordBox) { int numberOfWord = 0; int numberOfDigit = 0; int numberOfSpecialChar = 0; int numberOfChar = 0; int totalWordChar = 0; int totalCharNotWord = 0; ulong totalNumberOfRecord = 1; ulong totalWordPossible = 1; double numberOfHourToCrack = 0; double numberOfMilliSecondsToCrack = 0; List<string> numberOfWordInString = new List<string>(); int totalNumberOfVariable = 0; var passwordBox = parameter as System.Windows.Controls.PasswordBox; string password = passwordBox.Password; //regex for special char Regex rgxSpecial = new Regex("[^a-z0-9]", RegexOptions.IgnoreCase); numberOfSpecialChar = rgxSpecial.Matches(password).Count; //regex for digit Regex rgxNumber = new Regex(@"\d", RegexOptions.IgnoreCase); numberOfDigit = rgxNumber.Matches(password).Count; // find alphabatic charcter Regex rgxNumberOfChar = new Regex("[a-z]",RegexOptions.IgnoreCase); numberOfChar = rgxNumberOfChar.Matches(password).Count; //split the password using special char and digit string[] splitedStringByNumber = rgxNumber.Split(password); foreach (string s in splitedStringByNumber) { string[] splitedStringBySChar = rgxSpecial.Split(s); foreach(string st in splitedStringBySChar) { if (st != String.Empty) { numberOfWordInString.Add(st); } } } using (Hunspell hunspell = new Hunspell("en-US.aff", "en-US.dic")) { for (int i = 0; i < numberOfWordInString.Count(); i++ ) { if (!hunspell.Spell(numberOfWordInString[i])) { //replace with empty string numberOfWordInString[i] = ""; } else // total possible record { int value; if (dicPossibleWord.TryGetValue(numberOfWordInString[i].Count(), out value)) { totalWordPossible = totalWordPossible *(ulong) value; } } } } numberOfWordInString.RemoveAll(x => x.Equals("")); numberOfWord = numberOfWordInString.Count(); //Find the character that is not a word foreach(string s in numberOfWordInString) { totalWordChar += s.Count(); } totalCharNotWord = numberOfChar - totalWordChar; //total number of varible digit + special char + number of word + number of charact totalNumberOfVariable = (numberOfDigit > 0 ? numberOfDigit : 0) + (numberOfSpecialChar > 0 ? numberOfSpecialChar : 0) + (numberOfWord > 0 ? numberOfWord : 0) + (totalCharNotWord > 0 ? totalCharNotWord : 0); // find the possible record search and use rendom to combo totalNumberOfRecord =(ulong)(Math.Pow(10, numberOfDigit) * totalWordPossible * Math.Pow(POSSIBLE_SPEC_CHAR,numberOfSpecialChar) * totalNumberOfVariable)/2; double test1 = (Math.Log(((0.65477472 * totalNumberOfRecord) / 3542) + Math.Exp(14.66556)) - 14.66556); double test2 = Math.Exp(14.66556); double test3 = 1.527243 * test1 * test2; numberOfMilliSecondsToCrack = (((1.527243) * (Math.Log(((0.65477472 * totalNumberOfRecord) / 3542) + Math.Exp(14.66556)) - 14.66556)) * 1000); Model.TimeToCrack = numberOfMilliSecondsToCrack.ToString("#.####") + " milliseconds"; if (numberOfWord == 0) { Model.Message = "Password has " + totalNumberOfRecord + " half time possible combination." + "It has " + totalNumberOfVariable + " Variable."; } else { Model.Message = "Password has " + totalNumberOfRecord + " half time possible combination." + "It has " + totalNumberOfVariable + " variable, including" + numberOfWord +" word."; } numberOfHourToCrack = Math.Round((numberOfMilliSecondsToCrack / (1000 * 60 * 60)),MidpointRounding.AwayFromZero); if (numberOfHourToCrack < 2) { Model.StrengthNumber = 33; Model.Color = "Red"; } else if (numberOfHourToCrack < 36) { Model.StrengthNumber = 66; Model.Color = "Yellow"; } else { Model.StrengthNumber = 100; Model.Color = "Green"; } } /* Password1 * What if there is no workd * 1. First search letter word exist * 2. The password has three varibale 2 word Pass, word and digit 1 * Assumption there is 1000 possible four letter word * 3. Possible record to search is 10 ^ 1 * (1000 * 1000) * 3 (number of variable) * 4. True combo will be Random (1,0) lets say 1/2 for test * 5. True combo will be 1/2 of 10 ^ 1 * (1000 * 1000) * 3 * 6. MTBF = 1/0.65477472 * [log (((0.0.65477472 * combo)/3542) + e^14.66556) - 14.66556 ] * 7. == 1.527243 * [log (((0.0.65477472 * combo)/3542) + e^14.66556) - 14.66556 ] */ }