Click here to Skip to main content
Click here to Skip to main content
Go to top

Encrypting Editor Notepad replacement

, 19 Mar 2013
Rate this:
Please Sign up or sign in to vote.
Source code for an encrypting editor Notepad replacement.
This is an old version of the currently published tip/trick.

Introduction

I love Notepad! It is my favorite editing tool. It is fast and simple. So, why would I write a replacement program?

CryptPad is intended to be nearly the same as Windows 7 Notepad. The primary purpose of the program is to provide optional file encryption. This is valuable for files which contain sensitive information. Unlike many other encryption solutions, this one only encrypts and decrypts one file at save and open. There is never a decrypted version of the file stored unless the operator specifies to remove the encryption. The file can be stored multiple places and moved freely always in encrypted form. Anyone who knows the encryption string can read the file with this program. I now use CryptPad to edit everything where I would have used Notepad.

Only ASCII is supported in the encryption functions. Non-ASCII characters will not be encrypted. My apologies to those whose language is not based on ASCII. The encryption algorithm is not particularly sophisticated but it is completely effective to block the curious and prying. This is not intended to be a high security solution!

Background

Because of the importance of maintaining multiple passwords for better security, I have a file with all the passwords in it that I use. This is also a security risk unless the file is encrypted. I have examined many encryption solutions and none does exactly what I need. I need to be able to transport and store an encrypted file anywhere I want. Encrypted drives are not what I need. It must never exist in decrypted form. Therefore I need a simple editor which opens, decrypts, edits, encrypts, and saves a file.

Using the code

I am providing the complete VS2010 project zip file with complete source code for CryptPad, the encrypting Notepad replacement program. The program is compiled with the .NET framework version 3.5, which is included automatically with the Windows 7 OS. The program has only been well used and tested with the Windows 7 OS.

The program has barely been used with the Windows 8 OS (Yuck!).

The program has not been tested with Windows Vista or XP. Unfortunately, the .NET framework version 3.5 is not installed in Windows Vista or XP so you will need to install it to use the program in Windows XP.

Program installation is recommended for a CryptPad directory under the Documents directory for an individual user. The Program files directory can be used for an administrator install for all users. "Open With" can be set to default to CryptPad for .SAFE files.

You might choose to set default to CryptPad for .TXT also to take advantage of the additional editing functions. A REG file is provided which contains all kinds of settings I use to make CryptPad the default editor. These have been used and tested on Windows 7.

Additional details about the program:

I hope you find the program useful and the source code instructive for picking up some ideas. I am interested in any problems you may find in the program and in particular any incompatibility as a Notepad replacement. I am also interested in your ideas about improving this simple program. I have learned a lot by examining the code of others. I hope examing my code will be useful to you.

Points of interest

The novel aspects of the program are the encryption. The program uses a quick and simple scrambling algorithm of addition/subtraction based on a secret encryption string provided by the operator. The program encrypts only ASCII so that I have a contiguous arithmetic range. The intent is to continue to use text rather than binary processing.

These example excerpts are not identical to the supplied source.

private string Encrypt (string str)
{
	StringBuilder st = new StringBuilder (str);
	for (int i = 0; i < st.Length; ++i)
	{
		int chr = st[i];
		if (isASCII ((char) chr))
		{
			chr = ' ' + ((E (i) + (chr - ' ')) % 95);
			st[i] = (char) chr;
		}
	}
	return st.ToString ();
}

private string Decrypt (string str)
{
	StringBuilder st = new StringBuilder (str);
	for (int i = 0; i < st.Length; ++i)
	{
		int chr = st[i];
		if (isASCII ((char) chr))
		{
			chr = ' ' + ((chr - 32) - E (i) + 95) % 95;
			st[i] = (char) chr;
		}
	}
	return st.ToString ();
}

The encryption string is scrambled with a psuedo-random number seeded with a checksum of the encryption string

private int E (int i)
{
return (encryption_string[i % encryption_string.Length]
 + i + i * random_seed) % 95;
}

// plus checksum for random_seed
private int Checksum2 (string str)
{
	int checksum = 0;
	for (int i = 0; i < str.Length; ++i)
	{
		checksum += str[i];
	}
	return checksum;
}

The program uses an additional XOR checksum placed in the file to catch typos in the encryption string. This is critical to verify input since the encryption string is password masked.

// xor checksum for in the file
private uint Checksum (string str)
{
	uint checksum = 0;
	for (int i = 0; i < 32; ++i)
	{
		checksum <<= 1;
		checksum ^= str[i % str.Length];
	}
	return checksum;
}

History

  • Version 1.3.0.0 released 2013-03-17:
    • Handle ANSI, UNICODE, and UTF-8 files. Provides conversions.
  • Version 1.2.0.0 released 2013-03-15:
    • Changed the program icon from a generic icon to a custom design.
    • Added the "Edit" option "Transpose" to switch the character to the left and right of the cursor. I don't know how often you have a problem with transposing characters as you type but it happens to me a lot.
    • Added registry file to automatically use CryptPad for selected file types.
  • Version 1.1.0.0 released 2013-03-08:
    • Added the QuickCrypt function.
    • Required the encryption string to be at least four characters. Strengthened the checksum and encryption header. Corrected loss of the '~' character. Scrambled the encryption string. Incompatible with version 1.0 encryption. You must copy and paste the plaintext of existing encrypted files from the version 1.0 program to the version 1.1 program and save with new encryption.
    • Corrected some confusion with the initial directory on a "Save As" after a command line open.
    • Finished the Replace function, corrected dialog inconsistencies, and improved Notepad similarity.
    • Changed Edit menu option "Capital&ize" to "&Initial Capital"
    • Increased textbox.MaxLength from 32KB to 15MB. Generate an error and fail the open if the file size is greater than 10MB. Generate a warning if the size is greater than 5MB.
  • Version 1.0.0.0 released 2013-03-01:
    • These are the new and changed features compared to Notepad.
    • Only ASCII is supported in the encryption functions. Non-ASCII characters will not be encrypted. The initial encryption algorithm is not particularly sophisticated but it is completely effective to block the curious and prying. This is not intended to be a high security solution!
    • Automatic random password generation for websites. The sophisticated password would be stored in the encrypted file so you don't have to remember it. A typical line or sequence of lines in the file would have the website address, the email address/username, and the password for a quick and simple copy and paste to login.
    • The file is held open to reduce accidental multiple change problems. Read share only. Therefore, a read-only option is allowed on open.
    • The secondary purpose is to provide some enhanced functionality for general file editing:
    • Uppercase, lowercase, capitalize selection conversion.
    • Word wrap toggle remembers cursor location. Unlike Notepad it does not jump you to the beginning of the document.
    • Replace All leaves the last changed selection highlighted instead of jump to the beginning.
    • Go To works with word wrap on though the meaning is changed to wrapped line numbers.
    • The default directory for "Open" and "Save as" is initially the documents directory and becomes the directory of the last opened or saved file in the current session.
    • The Verdana font at 12 point is used in all program controls. This provides higher visibility for easier readability.

License

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

Share

About the Author

Frank T. Clark
Systems Engineer Three Angels Broadcasting Network
United States United States
I am a Software Systems Design Engineer experienced with IEEE standards and the entire IEEE software development life cycle. Concept Exploration, Requirements, Design, Implementation, Test, Installation and Checkout, Operation and Maintenance. I enjoy working with people and solving customer problems.
 
I am currently employed as Information Technology Staff in the religious satellite broadcasting industry.

Comments and Discussions


Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
 
QuestionGPG Pinmembercspitzer29-Jul-14 10:37 
AnswerRe: GPG PinprofessionalFrank T. Clark29-Jul-14 10:49 
GeneralRe: GPG Pinmembercspitzer29-Jul-14 10:52 
GeneralRe: GPG PinprofessionalFrank T. Clark29-Jul-14 10:54 
QuestionMultiple mapping Pinmemberfeanorgem29-Jul-14 6:43 
AnswerRe: Multiple mapping PinprofessionalFrank T. Clark29-Jul-14 10:43 
GeneralRe: Multiple mapping Pinmemberfeanorgem29-Jul-14 12:55 
GeneralRe: Multiple mapping PinprofessionalFrank T. Clark1-Aug-14 11:07 
GeneralRe: Multiple mapping Pinmemberfeanorgem1-Aug-14 15:49 
QuestionClarifying what you mean... PinmemberMember 873926921-Jul-14 9:17 
AnswerRe: Clarifying what you mean... PinprofessionalFrank T. Clark21-Jul-14 11:33 
GeneralRe: Clarifying what you mean... PinmemberMember 873926927-Jul-14 1:57 
SuggestionRe: Clarifying what you mean... PinprofessionalFrank T. Clark27-Jul-14 2:28 
GeneralRe: Clarifying what you mean... PinprofessionalFrank T. Clark28-Jul-14 4:36 
GeneralRe: Clarifying what you mean... PinmemberMember 87392693-Aug-14 2:02 
GeneralRe: Clarifying what you mean... PinprofessionalFrank T. Clark3-Aug-14 10:54 
GeneralRe: Clarifying what you mean... PinmemberMember 87392694-Aug-14 9:42 
QuestionApparently a file path cannot be relative? PinmemberMember 873926920-Jul-14 2:40 
AnswerRe: Apparently a file path cannot be relative? PinprofessionalFrank T. Clark20-Jul-14 4:26 
AnswerRe: Apparently a file path cannot be relative? PinprofessionalFrank T. Clark20-Jul-14 5:24 
AnswerRe: Apparently a file path cannot be relative? PinprofessionalFrank T. Clark21-Jul-14 8:54 
BugAbout window Pinmembermavru3-Jun-14 0:18 
GeneralRe: About window PinprofessionalFrank T. Clark3-Jun-14 3:09 
QuestionGreat article and very interesting! PinprofessionalVolynsky Alex6-Apr-14 12:51 
AnswerRe: Great article and very interesting! PinprofessionalFrank T. Clark7-Apr-14 2:39 
GeneralRe: Great article and very interesting! PinprofessionalVolynsky Alex7-Apr-14 8:05 
GeneralMy vote of 3 Pinmemberwebmaster4426-Apr-14 9:48 
GeneralRe: My vote of 3 PinprofessionalFrank T. Clark6-Apr-14 9:52 
GeneralRe: My vote of 3 PinmemberDave Cross7-Apr-14 2:15 
QuestionNo other editor with ANSI, UTF8 and Unicode support PinmemberAndreas Falco11-Feb-14 7:32 
AnswerRe: No other editor with ANSI, UTF8 and Unicode support PinprofessionalFrank T. Clark11-Feb-14 7:56 
GeneralRe: No other editor with ANSI, UTF8 and Unicode support PinmemberAndreas Falco11-Feb-14 8:48 
GeneralRe: No other editor with ANSI, UTF8 and Unicode support PinprofessionalFrank T. Clark11-Feb-14 9:45 
AnswerRe: No other editor with ANSI, UTF8 and Unicode support Pinmemberahagel7-Apr-14 8:46 
AnswerRe: No other editor with ANSI, UTF8 and Unicode support PinmemberOscar030-Jul-14 9:17 
QuestionAbsence of printing capability.. Pinmembermungball9911-Dec-13 5:26 
AnswerRe: Absence of printing capability.. [modified] PinprofessionalFrank T. Clark11-Dec-13 11:10 
GeneralRe: Absence of printing capability.. Pinmembermungball9916-Dec-13 8:55 
GeneralRe: Absence of printing capability.. PinprofessionalFrank T. Clark16-Dec-13 10:38 
QuestionI vote you 5 PinmemberWuRunZhe9-Dec-13 14:21 
AnswerRe: I vote you 5 PinprofessionalFrank T. Clark10-Dec-13 1:55 
GeneralMy vote of 5 PinprofessionalPrasad Khandekar23-Sep-13 21:36 
GeneralRe: My vote of 5 PinprofessionalFrank T. Clark24-Sep-13 2:10 
GeneralRe: My vote of 5 Pinmembermatrixcd20-Nov-13 20:41 
GeneralRe: My vote of 5 PinprofessionalFrank T. Clark21-Nov-13 3:27 
BugException when trying to save a file as safe without a key [modified] Pinmember_Nizar23-Sep-13 21:05 
GeneralRe: Exception when trying to save a file as safe without a key [modified] PinprofessionalFrank T. Clark24-Sep-13 2:09 
QuestionEncryption/Decryption Algorithm PinprofessionalMuhammad_Shoaib23-Sep-13 18:56 
AnswerRe: Encryption/Decryption Algorithm PinprofessionalFrank T. Clark24-Sep-13 2:08 
GeneralRe: Encryption/Decryption Algorithm PinmemberRick Bassham7-Oct-13 11:26 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 19 Mar 2013
Article Copyright 2013 by Frank T. Clark
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid