Click here to Skip to main content
15,885,309 members
Articles / Programming Languages / C#

Steganography 14 - What Text Lists, GIF Images, and HTML Pages have in common

Rate me:
Please Sign up or sign in to vote.
4.83/5 (31 votes)
22 Jan 2005CPOL4 min read 76.6K   2.2K   37  
A simple way to hide binary data in any kind of list
#region Using directives

using System;
using System.Collections.Specialized;
using System.Text;
using System.IO;

#endregion

namespace SteganoList {
    public class Utilities {
        private Utilities(){}

        internal static Stream ToStream(String text, bool prependLength)
        {
            BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());
            if (prependLength) {
                messageWriter.Write((byte)text.Length);
            }
            messageWriter.Write(Encoding.Default.GetBytes(text));
            messageWriter.Seek(0, SeekOrigin.Begin);
            return messageWriter.BaseStream;
        }

        internal static String GetTextFromFile(String fileName){
            String fileContent = String.Empty;
            if (fileName.Length > 0) {
                StreamReader reader = new StreamReader(fileName, Encoding.Default);
                fileContent = reader.ReadToEnd();
                reader.Close();
            }
            return fileContent;
        }

        internal static StringCollection SortLines(String[] lines, String alphabet)
        {
            String[] sortedLines = new String[lines.Length];
            Array.Copy(lines, sortedLines, lines.Length);

            if ((alphabet == null)||(alphabet.Length == 0)) {
                //use alphabet
                Array.Sort(sortedLines);
            } else {
                //user custom character order
                StringComparer comparer = new StringComparer(alphabet);
                Array.Sort(sortedLines, comparer);
            }

            StringCollection sortedList = new StringCollection();
            sortedList.AddRange(sortedLines);
            return sortedList;
        }

        internal static StringComparer GetStringComparer(String alphabetFileName)
        {
            StringComparer comparer = null;
            if (alphabetFileName.Length > 0) {
                StreamReader reader = new StreamReader(alphabetFileName, Encoding.Default);
                String fileContent = reader.ReadToEnd();
                reader.Close();
                comparer = new StringComparer(fileContent);
            }
            return comparer;
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
Corinna lives in Hanover/Germany and works as a C# developer.

Comments and Discussions