public void WriteToFile(string filename) { string dataToWrite = DateTime.Now.ToShortDateString(); Decoding.StringToBinary(dataToWrite); stream = new FileStream(filename, FileMode.Open, FileAccess.Write); writer = new StreamWriter(stream); try { writer.Write(Decoding.StringToBinary(dataToWrite)); } catch (FileNotFoundException fnfe) { MessageBox.Show(fnfe.Message); } catch (DirectoryNotFoundException dnfe) { MessageBox.Show(dnfe.Message); } catch (IOException ioe) { MessageBox.Show(ioe.Message); } finally { writer.Close(); //stream.Flush(); stream.Close(); } }
private void btnDecryption_Click_1(object sender, EventArgs e) { string filename = txtBrowse.Text; try { if (filename != null) { string messageDecrypted = ""; List <string> myList = new List <string>(); myList = fh.Readfile(filename); int shiftKey = 1; foreach (string line in myList) { string lineToCheck = Decoding.Caesar(line, shiftKey); //We check if the string is english or not... if (Regex.IsMatch(lineToCheck, "^[a-zA-Z0-9]*$")) { bool isSecret = Decoding.IsPalindrome(lineToCheck); Decoding.SendEmail(isSecret); messageDecrypted = messageDecrypted + " | " + lineToCheck; shiftKey = 1; } else { shiftKey += shiftKey; } //return messageDecrypted; } DBAccess dba = new DBAccess(); // // //Add the insert to database here... // // } } catch (Exception r) { MessageBox.Show(r.Message); } finally { fh.WriteToFile(filename); } }