Ejemplo n.º 1
0
        public static bool stegoChar(string txt, string fileName, string newFileName, int[] stegoKey, List <bool> compMsg)
        {
            long noChars = WordDocument.noChars(fileName);

            if ((noChars - 1) * 4 < txt.Length * 8)
            {
                return(false);
            }

            List <bool> msg;

            if (compMsg != null)
            {
                msg = compMsg;
            }
            else
            {
                msg = txtToBinary(txt);
            }


            string      coverString = WordDocument.returnDocument(fileName);
            List <char> cover       = coverString.ToCharArray().ToList();

            string stegoText = "";
            int    j         = 0;
            int    k         = 0;

            do
            {
                char pref = cover[k++];
                stegoText += pref;
                if (msg[j++])
                {
                    stegoText += Convert.ToChar(stegoKey[0]);
                }
                if (msg[j++])
                {
                    stegoText += Convert.ToChar(stegoKey[1]);
                }
                if (msg[j++])
                {
                    stegoText += Convert.ToChar(stegoKey[2]);
                }
                if (msg[j++])
                {
                    stegoText += Convert.ToChar(stegoKey[3]);
                }
            } while (k < cover.Count - 1 && j < msg.Count);


            if (k < cover.Count - 1)
            {
                stegoText += coverString.Substring(k);
            }

            WordDocument.createWord(stegoText, newFileName);

            return(true);
        }
Ejemplo n.º 2
0
        public static bool stegoJustification(string txt, string fileName, string newFileName)
        {
            List <int> linesNum;
            bool       broj = WordDocument.justificationMax(fileName, txt.Length * 8, out linesNum);

            if (!broj)
            {
                return(false);
            }
            List <bool>   msg   = txtToBinary(txt);
            List <string> lines = WordDocument.returnLines(fileName, msg, linesNum);

            WordDocument.createWord(string.Join(" ", lines), newFileName);


            return(true);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }