Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / MFC

SteganoPad - Steganographic Notepad

Rate me:
Please Sign up or sign in to vote.
3.67/5 (6 votes)
24 Dec 2008CPOL4 min read 33.4K   991   12   8
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)


Written By
Team Leader Product Based MNC
India India
Working in the graphics devision of a leading MNC.
Having 5+ yrs experience on c, c++, MFC.
Have exposure to C# and asp.net.

Also have good experience in flash & flex.



http://niscience.blogspot.com

Comments and Discussions

 
QuestionUnicode support? Pin
Mehmet Suyuti Dindar17-Jan-10 22:36
Mehmet Suyuti Dindar17-Jan-10 22:36 
QuestionIs it possible to override the display code instead of the keypress event-handling code? Pin
wtwhite1-Jan-09 21:53
wtwhite1-Jan-09 21:53 
AnswerRe: Is it possible to override the display code instead of the keypress event-handling code? Pin
nbugalia5-Jan-09 20:51
nbugalia5-Jan-09 20:51 
GeneralRe: Is it possible to override the display code instead of the keypress event-handling code? Pin
wtwhite5-Jan-09 21:07
wtwhite5-Jan-09 21:07 
GeneralNice tool !! Pin
hee11-Jan-09 0:13
hee11-Jan-09 0:13 
GeneralRe: Nice tool !! Pin
nbugalia5-Jan-09 21:00
nbugalia5-Jan-09 21:00 
GeneralApp wont start Pin
Ashley Staggs24-Dec-08 11:18
Ashley Staggs24-Dec-08 11:18 
GeneralRe: App wont start Pin
nbugalia5-Jan-09 21:06
nbugalia5-Jan-09 21:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.