public static bool stego(string txt, string fileName, string newFileName) { int noWords = WordDocument.noWords(fileName); if (noWords - 1 < txt.Length * 8) { return(false); } List <bool> msg = txtToBinary(txt); string coverString = WordDocument.returnDocument(fileName); List <char> cover = coverString.ToList(); string stegoText = ""; int j = 0; int k = 0; do { char pref = cover[k++]; if (pref == ' ') { if (msg[j]) { stegoText += pref + " "; } else { stegoText += pref; } j++; } else { stegoText += pref; } } while (k < cover.Count - 1 && j < msg.Count); if (j < msg.Count) { if (msg[j]) { stegoText += " "; } else { stegoText += " "; } } if (k < cover.Count - 1) { stegoText += coverString.Substring(k); } WordDocument.createWord(stegoText, newFileName); return(true); }
public static Dictionary <char, int> stegoHuffman(string txt, string fileName, string newFileName) { List <bool> msg = new List <bool>(); HuffmanTree huffTree = new HuffmanTree(); txt += '\0'; huffTree.build(txt); huffTree.Root.Traverse1(); List <bool> encoded = huffTree.encode(txt); foreach (bool b in encoded) { msg.Add(b); } int noWords = WordDocument.noWords(fileName); if (noWords - 1 < msg.Count) { return(null); } string coverString = WordDocument.returnDocument(fileName); List <char> cover = coverString.ToCharArray().ToList(); string stegoText = ""; int j = 0; int k = 0; do { char pref = cover[k++]; if (pref == ' ') { if (msg[j]) { stegoText += pref + " "; } else { stegoText += pref; } j++; } else { stegoText += pref; } } while (k < cover.Count - 1 && j < msg.Count); if (j < msg.Count) { if (msg[j]) { stegoText += " "; } else { stegoText += " "; } } if (k < cover.Count - 1) { stegoText += coverString.Substring(k); } WordDocument.createWord(stegoText, newFileName); return(huffTree.Frequencies); }