Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

SteganoPad - Steganographic Notepad

3.67/5 (6 votes)
24 Dec 2008CPOL4 min read 34.1K   995  
Only the user can see the words on screen
Image 1

Introduction

This is my first article on The Code Project and I hope that I am adding something useful which I was unable to find on the Internet (including CodeProject).
Please don't forget to rate my article so that I can know how useful my contribution is. :)

Generally in the office environment, people often watch your screen when you are writing or reading some (personal) email or document. Many times you even don't know and others share your information by just looking at your screen and reading the content. SteganoPad ensures that only you know what you are writing and reading. This gives you basically the same effect as the password box. The only difference is that only the letters (A-Z, a-z) are hidden by '#'. This means that all other characters like space, comma, fullstop, numbers and everything else are visible on the screen and you have a clear idea of the word boundary and location.

Disclaimer

This section basically goes for the critics. I have seen a lot of articles in CodeProject where people criticize others rather than support them mainly because of some copied code. Personally, I am not in favor of reinventing the wheel when the inventor’s name is clearly mentioned.

The idea of this application totally belongs to me. Before developing this application, I even searched CodeProject and the Internet and did not find any similar/related application.
The clipboard copy code belongs to MSDN. I have just used it. To add ToolBar to the dialog, I have used code from Randy More's article - "How to display tooltips for a toolbar in a dialog".

The code for this application is written as my approach to achieve the application's behavior. As there are many ways to skin a cat, there are many ways to write code too! Ideas to do the same task in a different manner are welcome.

Using the Application

SteganoPad application is just like Notepad except that it does not let others read what is on the screen. Whenever any alphabet key (a-z, A-Z) is pressed, a '#' is printed on the screen. The real word under the mouse cursor is displayed on the status bar. 

Double clicking an encrypted word('####') converts that word into the real word. 

The refresh button reloads the textbox contents based on the hide check button. 

You can cut, copy or paste the contents to or from SteganoPad. The data on the clipboard will paste as ##### and data on editbox will be moved to clipboard as real text. 

File open & save buttons are also provided to open/save the data of the application from/to text file.

About the Code

This application is basically built upon the CSteganoEdit class, which is derived from the CEdit class.

The original text is stored in a member variable - m_OriginalText which is updated regularly based on user behavior.

C++
class CSteganoEdit : public CEdit
{
public:
	CSteganoEdit();
	virtual ~CSteganoEdit();

    inline  void SetMask(BOOL mask){ m_mask = mask; }
    
    LRESULT OnPaste (WPARAM wParam, LPARAM lParam);
    LRESULT OnCut   (WPARAM wParam, LPARAM lParam);
    LRESULT OnCopy  (WPARAM wParam, LPARAM lParam);
    LRESULT OnClear (WPARAM wParam, LPARAM lParam);

    BOOL    CopyToClipBoard (CString strCpy);
    void    SetOriginalText(CString StrData);
		void 		ShowSelectedText();
		void 		RefreshCtrl();        
    void		EmptyEditCtrl();
    void		OnMouseMove(UINT nFlags, CPoint point);
    void		SetStatusWindowPtr (CWnd *pStatusWnd);

    CString GetOriginalText();
    CString CopyFromClipBoard ();
    CString EncryptText (CString EncStr);
    CString GetWordFromPoint (CPoint pt);
    
    virtual BOOL PreTranslateMessage(MSG* pMsg);
private:
   CString  m_OriginalText;
   BOOL     m_mask;
   CWnd*    m_pStatusWindow;
  
protected:
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);

	DECLARE_MESSAGE_MAP()
};	

The encryption functionality of the application is achieved by overriding PreTranslateMessage which changes the keys pressed to '#' on the fly.

C++
BOOL CSteganoEdit::PreTranslateMessage(MSG* pMsg)
{
    if (pMsg->message == WM_CHAR && ::GetKeyState (VK_CONTROL) >= 0 && 
					::GetKeyState (VK_MENU) >= 0 )
    {
        if (isprint ((int)pMsg->wParam))
        {
            int CurStart, CurEnd;
            GetSel( CurStart, CurEnd );
            m_OriginalText.Delete (CurStart, CurEnd - CurStart);
            m_OriginalText.Insert (CurStart, (char)pMsg->wParam);

            if (m_mask == TRUE && ( 
			   (pMsg->wParam >= 65 && pMsg->wParam <= 90) || 
			   (pMsg->wParam >= 97 && pMsg->wParam <= 122)))
            {  
				pMsg->wParam = '#';
            }
        }
    }

    return CEdit::PreTranslateMessage(pMsg);
}

Editing of the encrypted text is done by capturing the WM_KEYDOWN message which handles Delete, Backspace and Enter keys.

C++
void CSteganoEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
    if (nChar == VK_DELETE)
    {
       int CurStart, CurEnd;
       GetSel( CurStart, CurEnd );
       if (CurStart == CurEnd)
       {
           CurEnd = CurEnd + 1;
       }
       m_OriginalText.Delete (CurStart, CurEnd - CurStart);
    }
    else if (nChar == VK_BACK)
    {
        int CurStart, CurEnd;
        GetSel( CurStart, CurEnd );
        if (CurStart == CurEnd)
        {
            CurStart = CurStart - 1;
        }
        m_OriginalText.Delete (CurStart, CurEnd - CurStart);
    }else if (nChar == VK_RETURN)
    {
        int CurStart, CurEnd;
        GetSel( CurStart, CurEnd );
        m_OriginalText.Delete (CurStart, CurEnd - CurStart);
        m_OriginalText.Insert (CurStart, "\r\n");
    }

    CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}	

Room for Improvement

There is a lot of scope for improvement in this application.

  • Right now, this application has the basic functionality to hide the text from other users, but it's still lacking the luxury :) like Undo, find, wordwrap, etc.
  • Also, as the text written on the screen is not visible to the user, there should be an auto spell checker, which automatically corrects if the user types something wrong.
  • There is an option to change the visible character from '#' to something else ( '*' or any word).

I will try to add the above-mentioned functionalities in future. (No commitment!)

Points of Interest

A similar but very little functionality can be achieved by using the Password style of editbox. In the password mode, the textbox does not provide features like:

  1. Multiline support
  2. Cut, Copy & Paste
  3. Temporary visibility of words

The most important difference is that in the Password style of edit box, every character is shown as a dot. This makes words in a line hard to detect, as no word boundary (space) is visible in between the two words.

History

  • 24th December, 2008: Initial post

License

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