コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static string stegoCharRet(string fileName, int[] stegoKey, string[] compressKey, List <string> table)
        {
            string      toRet  = "";
            List <char> lista  = WordDocument.returnChars(fileName);
            List <bool> binary = new List <bool>();
            int         end    = 0;
            int         bajt   = 0;
            int         i      = 0;
            List <int>  key    = stegoKey.ToList();

            while (i + 4 < lista.Count)
            {
                int group = 0;
                for (int j = 0; j < 4; j++)
                {
                    int value = (int)lista[i + 1];
                    int n     = key.IndexOf(value);
                    if (n < 0)
                    {
                        break;
                    }
                    for (int k = group; k < n; k++)
                    {
                        binary.Add(false);
                        group++;
                        end++;
                        bajt++;
                    }
                    if (group < 4)
                    {
                        binary.Add(true);
                        group++;
                        i++;
                        end = 0;
                        bajt++;
                    }
                }
                while (group < 4)
                {
                    binary.Add(false);
                    group++;
                    end++;
                    bajt++;
                }
                i++;
                if (table != null)
                {
                    if (binary.Count >= table.Count * 2)
                    {
                        break;
                    }
                }
                else
                {
                    if (end > 7 && bajt == 8)
                    {
                        break;
                    }
                    if (bajt == 8)
                    {
                        bajt = 0;
                    }
                }
            }
            if (table != null)
            {
                binary = groupDecompress(binary, table, compressKey);
            }
            toRet = binaryToString(binary);

            return(toRet);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            string tajnaPoruka = "ps";
            string newFileName;
            string newFileName1;
            string fileName1 = "ravno.docx";
            string fileName  = Path.GetFullPath(fileName1);
            string directory = Directory.GetCurrentDirectory();

            WordDocument.clearSpaces(fileName);
            while (true)
            {
                Console.WriteLine("\n");
                Console.WriteLine("Tajna poruka je: " + tajnaPoruka);
                Console.WriteLine("Unesite broj za zeljeni algoritam:");
                Console.WriteLine("1 - Metoda blanko znakova kod poravnatog teksta");
                Console.WriteLine("2 - Metoda blanko znakova kod neporavnatog teksta");
                Console.WriteLine("3 - ZWC metoda");
                Console.WriteLine("4 - Metoda koriscenja nevidljivih simbola");
                Console.WriteLine("5 - Metoda sa Hafmanovom kompresijom");
                Console.WriteLine("6 - Metoda sa enkripcijom");
                Console.WriteLine("7 - Promenite tajnu poruku");
                Console.WriteLine("q - kraj");
                string alg = Console.ReadLine();

                //1. algoritam - metoda blanko znakova kod poravnatog teksta
                if (alg == "1")
                {
                    newFileName1 = "stego1.docx";
                    newFileName  = Path.Combine(directory, newFileName1);
                    if (OpenSpace.stegoJustification(tajnaPoruka, fileName, newFileName))
                    {
                        Console.WriteLine("Stego fajl je kreiran.");
                        Console.WriteLine("Poruka iz stego fajla je: " + OpenSpace.stegoJustificationRet(newFileName));
                    }
                    else
                    {
                        Console.WriteLine("Predugacka poruka!");
                    }
                }
                //2. algoritam - metoda blanko znakova kod neporavnatog teksta
                else if (alg == "2")
                {
                    newFileName1 = "stego2.docx";
                    newFileName  = Path.Combine(directory, newFileName1);
                    if (OpenSpace.stego(tajnaPoruka, fileName, newFileName))
                    {
                        Console.WriteLine("Stego fajl je kreiran.");
                        Console.WriteLine("Poruka iz stego fajla je: " + OpenSpace.stegoRet(newFileName));
                    }
                    else
                    {
                        Console.WriteLine("Predugacka poruka!");
                    }
                }


                //3. algoritam - ZWC metoda
                else if (alg == "3")
                {
                    newFileName1 = "stego3.docx";
                    newFileName  = Path.Combine(directory, newFileName1);
                    if (OpenSpace.stegoZWC(tajnaPoruka, fileName, newFileName))
                    {
                        Console.WriteLine("Stego fajl je kreiran.");
                        Console.WriteLine("Poruka iz stego fajla je: " + OpenSpace.stegoZWCret(newFileName));
                    }
                    else
                    {
                        Console.WriteLine("Predugacka poruka!");
                    }
                }
                //4. algoritam - Metoda koriscenja nevidljivih simbola
                else if (alg == "4")
                {
                    newFileName1 = "stego4.docx";
                    newFileName  = Path.Combine(directory, newFileName1);
                    int[] stegoKey = { 8207, 8206, 8205, 8204 };
                    if (OpenSpace.stegoChar(tajnaPoruka, fileName, newFileName, stegoKey, null))
                    {
                        Console.WriteLine("Stego fajl je kreiran.");
                        Console.WriteLine("Poruka iz stego fajla je: " + OpenSpace.stegoCharRet(newFileName, stegoKey, null, null));
                    }
                    else
                    {
                        Console.WriteLine("Predugacka poruka!");
                    }
                }
                //5. algoritam - Metoda sa Hafmanovom kompresijom
                else if (alg == "5")
                {
                    newFileName1 = "stego5.docx";
                    newFileName  = Path.Combine(directory, newFileName1);
                    Dictionary <char, int> freq = OpenSpace.stegoHuffman(tajnaPoruka, fileName, newFileName);
                    if (freq != null)
                    {
                        Console.WriteLine("Stego fajl je kreiran.");
                        Console.WriteLine("Poruka iz stego fajla je: " + OpenSpace.stegoHuffmanRet(newFileName, freq));
                    }
                    else
                    {
                        Console.WriteLine("Predugacka poruka!");
                    }
                }
                // 6. algoritam - Metoda sa enkripcijom
                else if (alg == "6")
                {
                    newFileName1 = "stego6.docx";
                    newFileName  = Path.Combine(directory, newFileName1);
                    List <string> table;
                    string[]      compressKey = { "G1", "G2", "G3", "G4" };


                    byte[] iv;
                    byte[] key;
                    int[]  stegoKey = { 8207, 8206, 8205, 8204 };

                    bool ok = OpenSpace.stegoEncryption(tajnaPoruka, fileName, newFileName, out iv, out key, stegoKey, compressKey, out table);
                    if (ok)
                    {
                        Console.WriteLine("Stego fajl je kreiran.");
                        Console.WriteLine("Poruka iz stego fajla je: " + OpenSpace.stegoEncryptionRet(newFileName, iv, key, stegoKey, compressKey, table));
                    }
                    else
                    {
                        Console.WriteLine("Predugacka poruka!");
                    }
                }
                else if (alg == "7")
                {
                    Console.WriteLine("Unesite poruku: ");
                    tajnaPoruka = Console.ReadLine();
                }
                else if (alg == "q")
                {
                    break;
                }
            }
        }