public static string stegoHuffmanRet(string fileName, Dictionary <char, int> frequencies) { string toRet = ""; List <bool> binary = new List <bool>(); List <char> chars; chars = WordDocument.returnChars(fileName); HuffmanTree huffTree = new HuffmanTree(); huffTree.Frequencies = frequencies; huffTree.buildFromFrequences(); for (int i = 0; i < chars.Count; i++) { if (chars[i] == ' ') { string temp; if (chars[i + 1] == ' ') { binary.Add(true); i++; temp = huffTree.decodeChar(true); } else { binary.Add(false); temp = huffTree.decodeChar(false); } if (temp != string.Empty && temp != "\0") { toRet += temp; } if (temp == "\0") { break; } } } return(toRet); }
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); }