Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Encrypting Editor Notepad Replacement

, 28 Jul 2014 CPOL
A C# .NET 3.5 (Win7) Windows Forms Application with source code
CryptPad-SourceOnly.zip
CryptPad
CryptPad (read-only).lnk
CryptPad.suo
CryptPad
CryptPad.csproj.user
CryptPad.ico
CryptPad.png
Properties
Settings.settings
hack.safe
Script.CryptPad
SendTo.lnk
Settings.lnk
CryptPad.png
CryptPad.zip
CryptPad (read-only).lnk
CryptPad.suo
CryptPad.csproj.user
CryptPad.ico
CryptPad.png
Settings.settings
hack.safe
Script.CryptPad
SendTo.lnk
Settings.lnk
CryptPad.exe
CryptPad.png
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=utf-8">
<!-- "http://www.Frank-T-Clark.com/Professional/Papers/CryptPad/CryptPad.html" -->

<TITLE>
CryptPad Program
</TITLE>

<META NAME = "Author" CONTENT = "Frank T. Clark">
<META NAME = "Keywords" CONTENT = "CryptPad, encryption, Notepad, source code">
<META NAME = "Description" CONTENT = "Encrypting Editor Notepad Replacement with C# source code.">

<H1 ALIGN = "CENTER">
CryptPad Program
</H1>

<P ALIGN=CENTER>
<IMG SRC = "CryptPad.png">

<H2 ALIGN = "CENTER">
Encrypting Editor Notepad Replacement
</H2>

<H2 ALIGN = "CENTER">
C# .Net 3.5 (Windows&nbsp7)<BR>
Windows Forms Application<BR>
with source code
</H2>

<H2 ALIGN = "CENTER">
Version 3.0 Released 2014-07-27
</H2>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>
/<A HREF = "../../../index.html">Home</A>
/<A HREF = "../../Professional.html">Professional</A>
/<A HREF = "../index.html">Papers</A> /CryptPad

<P>
<A HREF = "../CryptPad28/CryptPad.html">
Cryptpad Program Version 2.8 released 2014-06-01</A>
</TABLE>

<HR WIDTH = 576 SIZE = 3>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2 ALIGN = CENTER>
Download Program and Source
</H2>

<P ALIGN = CENTER>
<A HREF = "CryptPad.zip">
CryptPad.zip</A>

<P ALIGN = CENTER>
<A HREF = "CryptPad-SourceOnly.zip">
CryptPad-SourceOnly.zip</A>

<HR WIDTH = 576 SIZE = 3>

<H2>
Contents
</H2>

<UL>
<LI>
<A href = "#Introduction">
Introduction</A>
<LI>
<A href = "#UTF">
ASCII, ANSI, UTF-8</A>
<LI>
<A href = "#Install">
Installing the Program</A>
<LI>
<A href = "#Program">
Using the Program</A>
<LI>
<A href = "#Code">
Using the Code</A>
<LI>
<A href = "#Interest">
Points of Interest</A>
<LI>
<A href = "#Notepad">
What Is Notepad?</A>
<LI>
<A href = "#Release">
Release History and Notes</A>
<LI>
<A href = "#Mouse">
TextBox Mouse/Keyboard Actions</A>
<LI>
<A href = "#Shortcuts">
CryptPad Keyboard Shortcuts</A>
<LI>
<A href = "#Automation">
Command Line Automation</A>
<LI>
<A href = "#Menu">
Menu Bar Functions</A>
</UL>

</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Introduction">
Introduction</A>
</H2>

<P>
I love Windows Notepad! I write all my HTML, Jscript, CMD scripts, and much more in Notepad. It is my favorite editing tool. It is fast and simple. So, why would I write a replacement program?

<P>
The primary purpose of the CryptPad program is to provide optional file encryption. This is valuable for files which contain sensitive information. Unlike many other encryption solutions, this one requires no installation, is very simple, and non-intrusive on the operating system. CryptPad 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 like any other file, but always in encrypted form. Anyone who knows the encryption string can read the file with this program.

<P>
You may refer to the section on
<A href = "#Encryption">
Encryption</A> for additional details.

<P>
It is important, for better security, to use different passwords on each website you visit. In order to maintain these multiple passwords, 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. The file must never exist in decrypted form. Therefore I need a simple editor which opens, decrypts, edits, encrypts, and saves a file.

<P>
I also want the encrypted text to remain plaintext and not binary so that the operator can use the encrypted text anywhere (such as by copy and paste) you can use plaintext. I also want the size of the data to remain as small as practical. Therefore, special encodings of binary encryptions do not serve my purposes.

<P>
You might notice my use of the word "operator". I am a little uncomfortable with the word "user". I am deeply steeped in the computer industry having worked over 40 years with computers since about 1971. I remember the use of the word "luser" (loser) by those educated ignoramuses who considered their priesthood as above the lowly computer user. There is also the unfortunate association with the phrase "drug user". Sensitivity may not be considered a "manly" trait but I treasure and practice this characteristic. I evaluate the use of words just as carefully as I evaluate the computer software I use and write.

<P>
Notice that I do not at any point describe CryptPad as a Notepad clone. A clone is an exact copy. Notepad has some very specific functionality, which I have not seen any simple Notepad clone duplicate completely. For example, the Undo function of Notepad has not been properly implemented in most advertised "clones". Undo is implemented wherever practical in CryptPad. I have also not seen a simple "clone" which properly implements UTF-8 and Unicode conversions or reads files with ANSI characters as Notepad and CryptPad do. Major Notepad replacement programs such as Notepad++ will support these character encodings.

<P>
CryptPad is intended to be nearly the same as Windows&nbsp7 Notepad. I have chosen not to include the printing function. I almost never use paper or printing! Those rare occasions when I might want to print I can just use Notepad. CryptPad is not a "clone" but is close enough to be a useful replacement. Now that I have created the source code for a replacement for Notepad, I have been adding functions useful in my daily editing work.

<P>
I also have a major problem with Notepad because it allows a problem I call parallel update. In parallel update, you already have a file open with edits but it goes to the background when you switch windows. Later you open the file again forgetting that you already had it open. You make new edits and close the file. You switch to the old window later forgetting (Is this forgetting because I have been programming for over forty years?) you had changed it in a new window and save it again. Your previous edits are lost! There are several sequences of events that can lead to data loss. The situation is even worse if you edit a file on a network share and somebody else edits the same file!

<P>
Unlike Notepad, CryptPad maintains the file in an opened state locked against parallel changes but shared with file readers. This protects the file against accidental parallel modification data loss problems. I have had this happen to me on occasion with Notepad. You can still lose changes but it will have to be by a deliberate sequence of actions and not by casual accident.

<P>
Cryptpad contains many small improvements and special tools beyond what Notepad provides useful for editing. The most significant other addition is the optional use of .NET Framework <A HREF = "#RegEx">
Regular Expression Synatx</A> for Find and Replace.

<P>
I hope you find the CryptPad program useful. I am interested in any problems you may find in the program and in particular any incompatibility as a Notepad replacement. I intend to keep the program as small and simple as practical. CryptPad will always be a switchblade not a Swiss Army knife.

<P>
I continue to use, modify, and test the CryptPad program. I will return periodically (every other month or so) to update this article and the source code with the latest fixes, improvements, and tweaks.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "UTF">
ASCII, ANSI, UTF-8</A>
</H2>

<P>
As you read about this program, you might like to ask me a question. What in the world is all this UTF-8 and Unicode nonsense!?

<P>
In the old days of microcomputers (about 1980), it was simple. (It wasn't really. Remember EBCDIC? But we will pretend it was simple.) All text files were 7 bit ASCII (American Standard Code for Information Interchange) characters. Notice the word "American" in ASCII. There are many people in the world, with many different languages and characters, and they need to be represented in daily computer use. There are also additional "American" characters in common use beyond plain ASCII.

<P>
There is a great deal of confusion about the subject of character encoding. If you are a detail oriented person and prepared for a heavy read, you can start here:

<P>
<A HREF = "http://en.wikipedia.org/wiki/UTF-8" target = "_blank">
http://en.wikipedia.org/wiki/UTF-8</A>

<P>
I will try to make it short and simple. When you are using typical ASCII characters, strict UTF-8 (without a BOM) is exactly the same thing. Most of your editing will be simple ASCII. This entire webpage is only ASCII. In most cases, you can just stop here.

<P>
The exception is for non-English languages and if you ever use characters such as Microsoft Word smart quotes and apostrophes. These are the "curved" typographical equivalents of the simple "straight" ASCII quote and apostrophe. The apostrophe has a curve and there is a different curve for beginning and ending a quote. There are many other types of special characters. Many of the other languages also require special characters.

<P>
There are two primary ways to represent these types of non-ASCII characters. The older way is with single 8 bit characters. This is when you see "Windows-1252" or other non-Unicode encodings. These encodings can be very complex and plagued with limitations. Notepad refers to this as "ANSI" encoding. Unicode makes the process simpler (but not simple) to support everybody's characters. UTF-8 was invented to support ASCII with no changes and optionally extend to Unicode characters using pairs or clusters of 8 bit characters.

<P>
If this short explanation made you curious to know more, then you are back to the heavy reading I mentioned earlier. You may also refer to the section on
<A href = "#Encoding">
Encoding</A> for additional details.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Install">
Installing the Program</A>
</H2>

<P>
An important feature of this editor is that it does not require a blind install program or administrator permission. I am using the term "blind" to refer to the fact that the extent of the changes made by the typical install program are completely hidden from you. I don't like things that are hidden.

<P>
The CryptPad program is completely stand-alone so a simple copy is the minimum needed to permanently "install" and use the program. You can carry it on a USB flash drive and use anywhere with Windows&nbsp7 or later. You can use it temporarily, anywhere, and immediately with no install, no permissions, and no problems directly from the USB flash drive.

<P>
At this point I should mention that the CryptPad program uses standard .NET persistent settings. The persistent settings are things like Word Wrap, Font, Status View, and Window Position. These settings are stored in a file named user.config, which is kept in a directory with a name similar to "%LOCALAPPDATA% (C:\Users\%USERNAME%\AppData\Local) \Frank_T_Clark_Software\CryptPad.exe_Url_*\". These settings are kept in a separate unique directory ("CryptPad.exe_Url_*") generated by Windows depending on the CryptPad version and where the program is run from.

<P>
The permanent CryptPad program "installation" location is recommended for a CryptPad directory under the Documents directory for an individual operator. This would be a directory named "%USERPROFILE% (C:\Users\%USERNAME%) \Documents\CryptPad". Just create the directory and copy the program into place. You could download the CryptPad.ZIP file to the Documents folder and extract into this directory. The download provides a documentation/help file, image file, and useful scripts, which can also be placed in this directory. The help file is also available online and may contain additional updated information.

<P>
If you wish, "Open With" can be set to default to CryptPad for the .SAFE encrypted files created by CryptPad. You might choose to set the default "Open With" to CryptPad for .TXT also to take advantage of the additional editing functions.

<P>
I do not provide a blind install program because I want you to know for absolute certain exactly what is required to use the program. Uninstall is very simple. Erase the program! Most Setup programs mysteriously make unknown changes to your computer. I won't even blindly change the registry for you. I do provide a readable CryptPadInstall.CMD script and a CryptPadAdd.REG file, which illustrates an install procedure you can use.

<P>
The CryptPadAdd.REG file used by the CryptPadInstall.CMD script contains all kinds of settings I use to make CryptPad the default editor. These have been used and tested on Windows&nbsp7. I now use CryptPad to edit everything where I would have used Notepad. I recorded the registry changes with the "Default Programs Editor" freeware download, which works great. It is highly recommended.

<P>
The CryptPadAdd.REG file contains registry entries to associate the CryptPad program as the default editor for the .SAFE and .TXT file types. The .HTML, .CMD, and .REG file types have a Context Menu (Right-Click) "Edit" option. All these file types also have a Context Menu option "Open (Read-only)". There is a CryptPadDelete.REG file, which contains delete codes for these registry entries. The CryptPadInstall.CMD file automatically copies the CryptPad program to the default "install" location and runs Regedit. The Install CMD script can also be run from the "install" directory to only add registry entries.

<P>
The "Program Files" directory can be used for an administrator install for all operators. This is supported by the provided "install" scripts. When the program is installed in the "Program Files" directory in a secure environment, it does not need special permissions for normal use. There is never an attempt made to write to the directory where the program is installed during normal operation of the program. The CryptPadInstallAdmin.CMD, CryptPadAddAdmin.REG, and CryptPadDeleteAdmin.REG files support administrator install and modification of the registry for all operators.

<P>
The administrator install option has not been well tested because I rarely use administrator permissions.  I was not able to get the install script to work on Windows Server 2008, but I didn't try very hard. A manual install was quite simple. Just copy the files and click CryptPadAddAdmin.REG. Even on my own personal computer I rarely use administrator permissions. The individual operator install has been heavily used and tested both in my workplace and at home.

<P>
I provide the complete source so you can know for certain exactly what the CryptPad program does. Compile it for yourself, if you want. Examining the code is not easy, unless you are already a C# programmer, but it is available, if it is a concern to you. By these methods, you can trust the software. There is so much out there that is not trustworthy. You don't have to trust me. Full disclosure is the best trust there is.

<P>
The CryptPad program is a C# Windows Forms application compiled in VS2010 Express with the .NET framework version 3.5, which is included automatically with the Windows&nbsp7 OS. The program requires nothing but the supplied source and standard Windows functionality with VS2010 Express. The program has only been well used and thoroughly tested with the Windows&nbsp7 OS. I tried to upgrade to VS2013 Express but there is a problem in the new version which keeps me from easily upgrading.

<P>
The CryptPad program has only been used a little with the Windows&nbsp8 OS (Yuck!). Maybe Windows&nbsp8.1 will be better...

<P>
The CryptPad program has not been used or tested with Windows Vista (another Yuck!) 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 Vista or XP. There are likely to be issues with the program on these operating systems. I don't use Windows Vista or XP anymore so I won't be able to help you.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Program">
Using the Program</A>
</H2>

Perhaps it will be helpful for me to describe a step by step procedure for creating an encrypted file.

<OL>
<LI>
Start the CryptPad program.
<LI>
Select File, Encryption
<LI>
Enter your encryption string and type the Enter key.
<LI>
Enter the same encryption string again and type the Enter key.
<LI>
Enter your data.
<LI>
Save your file.
<LI>
If you open the encrypted file in Notepad you will see "~!@#" and more nonsense characters. Close the file without making any changes.
<LI>
Open the encrypted file in CryptPad.
<LI>
Enter your encryption string and type the Enter key.
<LI>
There is your data...
</OL>

<P>
You may also add CryptPad encryption to an existing text file.

<OL>
<LI>
Open any text file with the CryptPad program.
<LI>
Select File, Encryption
<LI>
Enter your encryption string and type the Enter key.
<LI>
Enter the same encryption string again and type the Enter key.
<LI>
Save your file.
</OL>

<P>
It is also simple to remove CryptPad encryption from an existing encrypted text file.

<OL>
<LI>
Open any encrypted text file with the CryptPad program.
<LI>
Enter your encryption string and type the Enter key.
<LI>
Select File, Encryption
<LI>
Enter a blank string
<LI>
Enter a second blank string
<LI>
Save your file.
</OL>

<P>
The installation and use of the CryptPad program is <B>NOT</B> designed for the casual or novice operator! If you follow the instructions carefully, you will be able to install and use the program. The CryptPad program is as simple to use as Notepad. The minimum copy installation is very simple. Using "Open with" is not very hard either.

<P>
The readable CryptPadInstall.CMD and CryptPadAdd.REG files are also available to make a complete "install" of the CryptPad program. These have been carefully tested on the Windows&nbsp7 operating system.

<P>
<B>Warning!</B> The optional use of the CryptPadInstall.CMD and CryptPadAdd.REG files requires a high level of knowledge and sophisticated skill to understand the changes they make. You can do significant damage to the function of the Windows operating system using a .REG file which is just like using the Registry Editor. All the warnings you have seen about the dangers of the use of the Registry Editor apply to using a .REG file. You are usually safe using a prewritten .REG file created by a knowledgeable developer. You are usually safe when you carefully follow instructions created by a knowledgeable developer.

<P>
You are invited to go the Code Project (www.codeproject.com) forum where the CryptPad program is published to leave
<A HREF = "http://www.codeproject.com/Articles/563711/Encrypting-Editor-Notepad-replacement#_comments" target = "_blank">
comments</A>. Registration is required. Code Project is a gathering place for millions of software developers.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Code">
Using the Code</A>
</H2>

<P>
I am providing the complete VS2010 C# project zip file with the executable, documentation, and the complete source code for CryptPad, the encrypting editor Notepad replacement program for those who enjoy software code. You might be interested in adding your own special functionality.

<P>
I hope you find the source code instructive for picking up some ideas. I have learned a lot by examining the code of others. I hope examining my code will be useful to you.

<P>
The project contains numerous test files and various things I found useful to develop, test, and use CryptPad. Of particular interest are the "CryptPad (read-only)" and the "SendTo" shortcuts. Clicking the "SendTo" shortcut opens the directory where these shortcuts reside. You can drag and drop the "CryptPad (read-only)" shortcut on the "SendTo" shortcut to add a new item. There are many interesting and useful things you can do with the "SendTo" directory.

<P>
It is also particularly important to mention the CryptPadAdd.REG file. This file contains registry entries to provide the Windows Explorer, context menu, "Open With", type of associations to use CryptPad with various file extensions. You must edit the CryptPad.REG file to provide the location where the CryptPad.exe file is kept, if you do not use the recommended "Documents\Cryptpad" directory. Some of the entries provided by the CryptPadAdd.REG file cannot be duplicated by using only the "Open With" association functionality.

<P>
<B>Warning!</B> The use of a .REG file requires a high level of knowledge and sophistication. You can do significant damage to the function of the Windows operating system using a .REG file which is just like using the Registry Editor. All the warnings you have seen about the use of the Registry Editor apply to using a .REG file.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Interest">
Points of Interest</A>
</H2>


<UL>
<LI>
<A href = "#EncodingRecognition">
Automatic Encoding Recognition</A>
<LI>
<A href = "#EncryptionAlgorithm">
Encryption Algorithm</A>
<LI>
<A href = "#ReplacementMessagebox">
Replacement Messagebox</A>
<LI>
<A href = "#MainMenu">
Old Style Main Menu</A>
</UL>

<P>
There are several things in my code that are a bit different or unusual. I will describe some of these points of interest and the reasons why I used them. I made several unusual applications changes from the typical VS2010 project. I embedded the code for the main entry point for the application inside the primary form rather than having a separate file. Gettings rid of the extra file was a desirable choice for me.


<H3>
<A name = "EncodingRecognition">
Automatic Encoding Recognition</A>
</H3>

<P>
One of the many interesting features in the CryptPad program source code is the automatic detection of ANSI, UTF-8, and Unicode character encodings with Byte Order Mark (BOM) detection. This is a feature missing out of the simple Notepad "clones" I have seen. One of them implements it now because I told the writer how to do it. The .NET library provides all the support needed for automatic detection but doesn't tell you how to use it.

<P>
There are two pieces of information required and some sample code to demonstrate their use. I have seen many complicated solutions proposed for automatic detection but it is actually quite simple. I will mention that my assumption is that the file is properly encoded without encoding errors or malformed characters. This is a reasonable assumption for any properly written program (such as Notepad and CryptPad) used to create a file.

<P>
The first piece of necessary information is to recognize that the UTF-8 encoding has been carefully designed for automatic detection, which makes it vastly different than the complexities and ambiguities of ANSI encoding. It is highly unlikely (but possible) that an ANSI file would be mistaken as UTF-8. The other detection methods don't promise any better. I won't go into detail about this feature of the UTF-8 encoding.

<P>
The second piece of necessary information is to recognize that the .NET library implements automatic detection through exception handling when ANSI characters are found. Unfortunately, the documentation doesn't connect the dots for how to implement this automatic detection.

<P>
This sample code illustrates automatic detection of UTF-8 and other Unicode encodings with an exception handling fallback to ANSI encoding.

<P>
This simple (assuming you are a skilled C# programmer) example excerpt is not identical to the supplied source code.

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
file_stream = new FileStream (filename, FileMode.Open,
FileAccess.ReadWrite, FileShare.Read);

// UTF-8 encoding with automatic dection of other
// Unicode encodings and ANSI error detection
Encoding save_encoding = new UTF8Encoding (false,true);
StreamReader sr = new StreamReader (file_stream,
&nbsp;&nbsp;&nbsp;&nbsp;save_encoding, true);

string str = null;
try
{
&nbsp;&nbsp;&nbsp;&nbsp;str = sr.ReadToEnd ();
&nbsp;&nbsp;&nbsp;&nbsp;// Save the actual encoding for later write
&nbsp;&nbsp;&nbsp;&nbsp;save_encoding = sr.CurrentEncoding;
}
catch
{
&nbsp;&nbsp;&nbsp;&nbsp;// ANSI error detection
&nbsp;&nbsp;&nbsp;&nbsp;save_encoding = null;
}
if (null == save_encoding)
{
&nbsp;&nbsp;&nbsp;&nbsp;// use ANSI from the default code page
&nbsp;&nbsp;&nbsp;&nbsp;save_encoding = Encoding.GetEncoding (0);
&nbsp;&nbsp;&nbsp;&nbsp;file_stream.Position = 0;
&nbsp;&nbsp;&nbsp;&nbsp;sr = new StreamReader (file_stream,
save_encoding);
&nbsp;&nbsp;&nbsp;&nbsp;str = sr.ReadToEnd ();
}

... modify str

// discard any previous contents
file_stream.SetLength (0);

// use StreamWriter with the same encoding
StreamWriter sw = new StreamWriter (file_stream,
&nbsp;&nbsp;&nbsp;&nbsp;save_encoding);
sw.Write (str);
</PRE>
</TABLE>

<H3>
<A name = "EncryptionAlgorithm">
Encryption Algorithm</A>
</H3>

<P>
The most novel aspect of the CryptPad program source code is the encryption. The program uses a quick and simple double 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. My apologies to those whose language is not based on ASCII. The intent is to continue to use text rather than binary processing. The encryption is highly efficient and adds only 21 bytes to the size.

<P>
It is possible to use Base64 or similar encoding to convert the entire Unicode string to ASCII for the encryption. This would add a lot of overhead in processing and size. Using any standard encryption would have the same effect. These other methods would also add a lot of complexity to the program. This quick, simple, and effective solution serves my purposes the best.

<P>
These simple example excerpts are not identical to the supplied source code.

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

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

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

<P>
The encryption string is scrambled with a pseudo-random number seeded with a checksum of the encryption string

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

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

// plus checksum for random_seed
private int ChecksumAdd (string str)
{
&nbsp;&nbsp;&nbsp;&nbsp;int checksum = 0;
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i < str.Length; ++i)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checksum += str[i];
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return checksum;
}
</PRE>
</TABLE>

<P>
The CryptPad program uses an additional XOR checksum placed in the file to verify whether the encryption string is correct when attempting to decrypt. I protect short encryption strings by extending it to at least 32 characters. The purpose is to protect the operator from a wrong decryption and warn them, if they mistype the encryption string.

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
// xor checksum for in the file
private uint ChecksumXOR (string str)
{
&nbsp;&nbsp;&nbsp;&nbsp;uint checksum = 0;
&nbsp;&nbsp;&nbsp;&nbsp;int j = 32;
&nbsp;&nbsp;&nbsp;&nbsp;if (32 < str.Length)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j = str.Length;
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i < j; ++i)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint t = 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (0 < (0x80000000 &
checksum))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t
= 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checksum <<= 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checksum |= t;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checksum ^= str[i %
str.Length];
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return checksum;
}
</PRE>
</TABLE>

<P>
I use a second XOR checksum to detect whether the encrypted data has been corrupted by being modified without being decrypted. This would destroy the integrity of the encrypted data. The operator would be notified immediately upon attempting to open the file whether the encrypted data had been modified and corrupted. If the '~!@#$' encryption header is modified, then the data is assumed to be non-encrypted and displayed without decryption.

<P>
I would not claim the encryption used by the CryptPad program is CIA quality but I think you will find it is highly effective. The strength of the encryption is highly dependent on the length of the encryption string. A strong string of ten characters or more is not likely to be broken by anyone except a skilled cryptologist. I am not a skilled cryptologist but I am familiar with some aspects of cryptology. The primary attacks against this encryption have been anticipated.

<P>
I am offering a challenge to see if a clever hacker or skilled cryptologist will take an interest and break my encryption. I have included a file called "hack.safe" in the zip file. If you can break my encryption, please post the results in the discussion with the encryption string. Anyone can verify your success. I would be interested to know how you did it, how long it took, and what type of equipment was needed.

<P>
The most likely attack would be against the XOR checksum used to verify the encryption string against typographical error. The success of this type of attack depends on the strength of the encryption string you choose.

<P>
The suggestion has been made that I should use the File.Encrypt method. I do not want a decrypted version of the file to ever reside on any drive for any period of time. I want to be able to carry the file anywhere I want and use anywhere I want. CryptPad.exe can be carried with the encrypted file (such as on a USB drive) and used anywhere to read the file without any installation or removal and there is never a trace of the decrypted file on the computer (Well, maybe in memory or in the paging file...). I want the encryption to be text that I can copy and paste anywhere. The File.Encrypt method does not meet any of those criteria. I have seen nothing that meets these criteria.

<P>
The suggestion has also been made that I should use an industry defined standard encryption method. This would result in binary files. I want to use only methods that produce plain text so that the encryption can be pasted into email, instant messages, and wherever plain text would normally be used. It is possible to Base64 encode the result. I do not wish for the file size to increase by a significant amount. Standard encryption methods also increase the complexity and processing of the program.

<P>
Those who wish to use an industry defined standard encryption method and support Unicode can modify the program to their requirements. I am happy with a simple and fast ASCII encryption process.

<H3>
<A name = "ReplacementMessagebox">
Replacement Messagebox</A>
</H3>

<P>
I have included my own version of a simple partial replacement similar to the standard MessageBox. I have examined many other replacements for the standard MessageBox and found them to be too complicated for my simple purposes. These were my requirements:

<UL>
<LI>
The MessageBox dialog must center on the CryptPad window rather than center on the screen.
<LI>
Allow the text of the message to be copied to the clipboard and pasted in a text file to be shared in problem reports or whatever.
<LI>
Snap the cursor to the default button.
<LI>
The class is a single file generic drop into any application.
<LI>
Keep It Simple!
</UL>

The Messagebox.cs file is a composite of three files developed and tested separately first using the designer then combined.

<H3>
<A name = "MainMenu">
Old Style Main Menu</A>
</H3>

<P>
One of the things that makes my code a little unusual is the use of the older System.Windows.Forms.MainMenu control instead of the System.Windows.Forms.MenuStrip control. I prefer the simple view and layout of the older control. This is not in the standard VS2010 toolbox but is easily added to the project and still supported by the Form Designer.

<P>
With an example form called Form1, add the following lines to the Form1.Designer.cs file to begin using the MainMenu control.
	
<P>
After the beginning of the InitializeComponent function:

<PRE>
private void InitializeComponent ()
{
</PRE>

<P>
Add:

<PRE>
this.mainMenu = new System.Windows.Forms.MainMenu ();
this.Menu = this.mainMenu;
</PRE>

<P>
At the end of the file after:

<PRE>
#endregion
</PRE>

<P>
Add:

<PRE>
private System.Windows.Forms.MainMenu mainMenu;
</PRE>

<P>
Click on the mainMenu icon in the "Form1.cs [Design]" tab and start entering menu items. Sometimes you must close the tabs and open them again.

</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Notepad">
What Is Notepad?</A>
</H2>

<UL>
<LI>
<A href = "#Explorer">
What Is Windows Explorer?</A>
<LI>
<A href = "#Plaintext">
What Is Plain Text?</A>
<LI>
<A href = "#TextBox">
What Is the TextBox?</A>
<LI>
<A href = "#CryptPad">
How is CryptPad different?</A>
</UL>

Notepad is the basic text editing tool provided by the Windows operating system to view or edit plain text files. A text file is a file type typically identified by the .TXT file name extension. There are other extensions which contain text, which I often edit with Notepad.

<P>
Notepad has several specific important characteristics to note beside the fact it is a plain text editor. Probably the next most important characteristic of Notepad is that the entire file is completely loaded into memory while editing. This makes Notepad fast for the typical file of about 64k or less. However this is a problem when editing multi-megabyte files. The good news is that Windows&nbsp7 Notepad and CryptPad can do it but the bad news is that it slows down pretty quickly. You usually don't need to do this very often.

<P>
Another important characteristic is that it supports all the standard file encodings. ANSI, UTF-8 (ASCII), Unicode (UTF-8), Unicode, and Unicode (Big-Endian).

<H3>
<A name = "Explorer">
What Is Windows Explorer?</A>
</H3>

<P>
It is important to understand that Notepad is tightly integrated with Windows Explorer. The CryptPad program can also be tightly integrated with Windows Explorer. Windows Explorer is my primary development platform or environment for general purposes. Most developers understand this. A beginning computer operator may not understand the importance of Windows Explorer, which is also known as "My Computer". Many people use the "Desktop" as their primary launch platform. The "Desktop" is actually a simple view of Windows Explorer. I primarily use Windows Explorer as my launch platform.

<P>
The first thing I always do on a new computer is enable the icon for "My Computer" on the "Desktop". I also always rename it to the name of the computer because I remote to so many computers so often, it helps to have a little reminder of what computer I am using. Many times the first thing I click on the desktop is "My Computer" or Windows Explorer.

<P>
I am very particular about how Windows Explorer is configured. It is vitally important that all file information be displayed. The second thing I always do on a new computer is enable file details in Windows Explorer. The third thing I do is change the default Layout to show the Navigation pane. I also like the Details pane.

<H3>
<A name = "Plaintext">
What Is Plain Text?</A>
</H3>

<P>
All files can be placed in two general categories. Text files are designed primarily to be read by a person. Binary files are designed primarily to be read by a computer program. Binary files may contain text but text files almost never contain binary data.

<P>
A proper plain text file contains only printing characters designed to be read by a person. The file will contain the ASCII CR/LF control characters to indicate the end of a line and the ASCII HT (TAB) control characters to arrange text in columns. Any other ASCII control characters are improper. Some of the ASCII control characters are actually encoded to a printable Unicode character. It is also improper in a typical Windows file for there to be ASCII CR or LF control characters which are not part of a CR/LF pair.

<H3>
<A name = "TextBox">
What Is the TextBox?</A>
</H3>

<P>
Notepad is based on the Windows TextBox control which provides most of the editing functionality. Notepad and TextBox are both a bit short on documentation for their functionality but are mostly simple. The Help option in Notepad does little more than provide answers to some common simple questions about Notepad. At least the pieces of Notepad functionality are listed in the menu options. There are a lot of questions left unanswered about how the functions are performed. This documentation file answers those questions for the CryptPad implementation of Notepad functionality.

<P>
TextBox is the primary input control for Windows. Almost all other Windows input functionality either expands or imitates the basic functionality of TextBox. I am providing some additional description about editing with the TextBox in the CryptPad Help and website documentation.

<H3>
<A name = "CryptPad">
How is CryptPad different?</A>
</H3>

The basic use of CryptPad is mostly identical to Notepad. The design of the CryptPad program is similar to Notepad. CryptPad is also based on the TextBox control. The primary difference of CryptPad from Notepad is a lack of support for printing. You may use Notepad, when you wish to print. CryptPad adds support for encryption, file locking, .NET Framework <A HREF = "#RegEx">
Regular Expression Synatx</A>, and automatic backup. CryptPad provides other functionality beyond Notepad.

<P>
Cryptpad describes its functionality in more detail than Notepad provides. The documentation assumes you know how to use Notepad so it primarily describes what is different from Notepad. The documentation also describes some of the more mysterious operations it shares with Notepad. The computer elite love murky software operation, which needs to be researched to discover and then remembered. I believe in documentation, which is disdained among many of those who consider themselves skilled in computer usage and software development. Maybe they can't or won't read plain English and assume nobody else does either.

<P>
CryptPad uses the operator specified Message Box system font and size in all CryptPad dialogs. Those with young good eyes can use the default 8pt or whatever while those with older poor eyes can use Control Panel, Personalization, Window Color and Appearance to specify what we need. I prefer Verdana 12pt. This works fine on Windows&nbsp7 but Microsoft in their great wisdom does not appear to allow us to specify our own font on Windows&nbsp8! Changing the font size on Windows&nbsp8 is also awkward, as is much of Windows&nbsp8. (Did I already say? Yuck!) Who do I complain to that will listen and do something for the handicapped or visually limited?

<P>
The most useful functionality for developers is the error checking for misplaced control characters and other checking and correcting functions. CryptPad is also more helpful and functional than Notepad without losing the basic simplicity and speed.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Release">
Release History and Notes</A>
</H2>

A history of changes to the CryptPad program and release notes.

<UL>
<LI>
Version 3.0 Released 2014-07-27:

<UL>
<LI>
Corrected link case error of 'CryptPad' not 'Cryptpad' in Help, Online Contents and Help, About description.
<LI>
Corrected an error and some lingering confusion about the current directory handling.
<LI>
Streamlined some of the settings code and other minor code changes.
<LI>
Added AcceptButton and CancelButton to the Messagebox class so that even if the focus is on the textbox you can still use the Enter key or the ESC key.
<LI>
Added a combobox for the find and replace dialogs as a reminder and automatic insert for special non-Regex patterns and some of the most common Regex patterns. With the introduction, development, and testing of Regex the version is bumped to a 3.0 release.
</UL>

<LI>
Version 2.8 Released 2014-06-01:

<UL>
<LI>
Corrected the special functionality of "Replace All" when there is only a single non-RegEx replacement.
<LI>
Improved the documentation of the RegEx implementation after further use and testing.
<LI>
Other minor documentation improvements.
</UL>

<LI>
Version 2.7 Released 2014-04-06:

<UL>
<LI>
Added <A HREF = "#RegEx">
Regular Expression Syntax</A> to <A href = "#Find">
Find</A> and <A href = "#Replace">
Replace</A>.

<P>
This option is brand new and not thoroughly tested!

<LI>
Corrected name errors in the CryptPadAdminInstall script.
<LI>
Made sure both install scripts included both install option files.
<LI>
Slight change to the
<A href = "#CRLF">
Force CR/LF (Windows)</A> and
<A href = "#LF">
Force LF (UNIX)</A> tools to preserve a dangling CR.
</UL>

<LI>
Version 2.6 released 2014-02-09:

<UL>
<LI>
Changed the handling of the current directory.
<LI>
Added a conversion to support using the echo command to create a quote in an automation script. In this case you may use "\q" to indicate a quote.
<LI>
Improved RestoreCaretPosition function and corrected occasional exception errors when the number of lines changes and the current caret position is near the end of the document.
</UL>

<LI>
Version 2.5 released 2013-12-08:

<UL>
<LI>
Window Position Setting fixed.
<LI>
Saved the Replace string on a Find Next so it is not lost, if followed by a Cancel.
<LI>
Rearranged code a little bit to more accurately group related functions.
<LI>
I did some tweaks of control spacing on the find and replace dialogs.
</UL>

</UL>

</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Mouse">
TextBox Mouse/Keyboard Actions</A>
</H2>

In order to better understand and describe the actions of the mouse and the keyboard in the TextBox we need to define some terms.

<DL>
<DT>
Caret
<DD>
The position in a TextBox where the next character typed on the keyboard will be inserted. This position is marked with a blinking vertical bar.
<DT>
Pointer
<DD>
The cursor displayed by the mouse, which marks where the action of a mouse click is applied. When the cursor is over the TextBox it is usually shaped like a tall and thin capital letter "I" known as the I-beam.
<DT>
<A name = "Word">
Word</A>
<DD>
The definition of a "word" is complex but it is important to be able understand wrap and other functions. Generally speaking a "word" of text begins after a space, question mark "?", exclamation mark "!", closing brace "}", closing bracket "]", closing parenthesis")", vertical bar "|", and hypphen "-" or before a dollar sign "$", percent sign "%", plus sign "+", backslash "\", opening brace "{", opening bracket "[", and opening parenthesis "(".
<!-- Word Testing string xx~xx!xx@xx#xx$$$xx%%%xx^xx&xx*xx(xx)xx_xx+++xx=xx`xx-xx[xx]xx\\\xx|xx{xx}xx'xx;xx:xx"xx/xx.xx,xx<XX>xx?xx -->

<P>
The hard newline is both a before and after word break character but is a word itself and is never included in another "word". Multiple word break characters are usually combined and included in the definition of the "word". Only one leading word break character of dollar sign "$", percent sign "%", plus sign "+", and backslash "\" is included in the definition of the "word". Punctuation such as single/double quote, period, comma, colon, and semicolon and all other characters is included in the definition of a "word". Confusing? These are the rules I have observed for ASCII characters. It is impossible to know if this is a complete list without adequate Microsoft documentation or careful testing. ANSI or Unicode...?
</DL>

These are some of the mouse shortcuts used in a TextBox. It is impossible to know if this is a complete list without adequate Microsoft documentation or careful testing.

<DL>
<DT>
Click
<DD>
Move the caret to the current location of the mouse pointer.
<DT>
Right-Click
<DD>
Pop-up up the context menu.
<DT>
Double-Click
<DD>
Select the "word" under the mouse pointer.
<DT>
Click-Drag
<DD>
Select the text under the beginning location of the mouse pointer through the final location of the mouse pointer.
<DT>
Double-Click-Drag
<DD>
Select the "word" under the beginning location of the mouse pointer through the "word" under the final location of the mouse pointer.
<DT>
Shift-Click
<DD>
Select the text from the caret to the pointer.
<DT>
Shift-Double-Click
<DD>
Select the text from the caret to the "word" at the pointer.
</DL>

This is a list of the TextBox keyboard shortcuts grouped by function. It is impossible to know if this is a complete list without adequate Microsoft documentation or careful testing.

<H3>
Moving the Caret
</H3>

<DL>
<DT>
Right
<DD>
Move the caret one character position to the right.
<DT>
Left
<DD>
Move the caret one character position to the left.
<DT>
Up
<DD>
Move the caret one line up.
<DT>
Down
<DD>
Move the caret one line down.
<DT>
Home
<DD>
Move the caret to the beginning of the line.
<DT>
End
<DD>
Move the caret to the end of the line.
<DT>
PageUp
<DD>
Scroll the TextBox window down placing the top line on the bottom line and keeping the caret at about the same position in the window.
<DT>
PageDown
<DD>
Scroll the TextBox window up placing the bottom line on the top line and keeping the caret at about the same position in the window.
<DT>
Ctrl+Right
<DD>
Move the caret right to the start of the next word position.
<DT>
Ctrl+Left
<DD>
Move the caret left to the start of the previous word.
<DT>
Ctrl+Home
<DD>
Move the caret to the beginning of the text.
<DT>
Ctrl+End
<DD>
Move the caret to the end of the text.
</DL>

<H3>
Selecting Text
</H3>

<DL>
<DT>
Shift+Right
<DD>
Extend selection one character to the right.
<DT>
Shift+Left
<DD>
Extend selection one character to the left.
<DT>
Shift+Down
<DD>
Extend selection down one line.
<DT>
Shift+Up
<DD>
Extend selection up one line.
<DT>
Shift+Home
<DD>
Extend selection to beginning of line.
<DT>
Shift+End
<DD>
Extend selection to end of line.
<DT>
Shift+PageUp
<DD>
Scroll the TextBox window down placing the top line on the bottom line and keeping the caret at about the same position in the window extending the selection.
<DT>
Shift+PageDown
<DD>
Scroll the TextBox window up placing the bottom line on the top line and keeping the caret at about the same position in the window extending the selection.
<DT>
Shift+Ctrl+Right
<DD>
Extend selection to next word.
<DT>
Shift+Ctrl+Left
<DD>
Extend selection to previous word.
<DT>
Shift+Ctrl+Home
<DD>
Extend selection to top of text.
<DT>
Shift+Ctrl+End
<DD>
Extend selection to bottom of text.
</DL>

<H3>
Cut, Paste, and Undo
</H3>

<DL>
<DT>
Ctrl+C, or Ctrl+Ins
<DD>
Copy selected text into the clipboard.
<DT>
Ctrl+V, or Shift+Ins
<DD>
Paste selected text from the clipboard.
<DT>
Ctrl+X, or Shift+Del
<DD>
Cut selected text into the clipboard.
<DT>
Ctrl+Z
<DD>
Undo last edit.
</DL>

<H3>
Deleting Text
</H3>

<DL>
<DT>
Del
<DD>
Delete the character right of the caret or the current selection.
<DT>
Backspace, or Ctrl-H
<DD>
Delete the character left of the caret or the current selection.
<DT>
Ctrl+Del
<DD>
Delete to the end of the line or the current selection.
</DL>

<H3>
Inserting Text
</H3>

<DL>
<DT>
Any ASCII graphic character
<DD>
Insert the character typed at the caret location.
<DT>
Enter, Ctrl-M, Ctrl-J
<DD>
Insert CR/LF at the caret location and begin a new line.
<DT>
TAB, or Ctrl+I
<DD>
Insert a Tab (HT) character at the caret location. CryptPad steals Ctrl+I from the Textbox for the Initial Capital shortcut, if there is a current selection.
</DL>

<H2>
<A name = "Shortcuts">
CryptPad Keyboard Shortcuts</A>
</H2>

This is an alphabetical list of the CryptPad function keys and keyboard shortcuts. The shortcuts shared with the TextBox are marked with an asterisk "*".

<DL>
<DT>
Ctrl+A
<DD>
Edit, Select All
<DT>
* Ctrl+C
<DD>
Edit, Copy
<DT>
Ctrl+F
<DD>
Edit, Find
<DT>
Ctrl+F1
<DD>
Help, Online Contents
<DT>
Ctrl+G
<DD>
Edit, Go To
<DT>
Ctrl+H
<DD>
Edit, Replace
<DT>
Ctrl+I
<DD>
Edit, Initial Capital
<DT>
Ctrl+L
<DD>
Edit, Lowercase
<DT>
Ctrl+N
<DD>
File, New
<DT>
Ctrl+O
<DD>
File, Open
<DT>
Ctrl+Q
<DD>
Tools, QuickCrypt
<DT>
Ctrl+S
<DD>
File, Save
<DT>
Ctrl+T
<DD>
Edit, Transpose
<DT>
Ctrl+U
<DD>
Edit, Uppercase
<DT>
* Ctrl+V
<DD>
Edit, Paste
<DT>
* Ctrl+X
<DD>
Edit, Cut
<DT>
* Ctrl+Z
<DD>
Edit, Undo
<DT>
F1
<DD>
Help, Local Contents
<DT>
F3
<DD>
Edit, Find Next
<DT>
F5
<DD>
Edit, Date/Time
<DT>
F6
<DD>
Tools, Password
<DT>
Shift-F3
<DD>
Edit, Find Previous
</DL>

</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Automation">
Command Line Automation</A>
</H2>

<UL>
<LI>
<A href = "#DOSCRIPT">
DO SCRIPT</A>
<LI>
<A href = "#DOANSI">
DO ANSI</A>
<LI>
<A href = "#DOUTF-8">
DO UTF-8</A>
<LI>
<A href = "#DOREADONLY">
DO READONLY</A>
<LI>
<A href = "#DOEDIT">
DO EDIT</A>
<LI>
<A href = "#DOREPLACE">
DO REPLACE</A>
<LI>
<A href = "#DOREPLACEMATCH">
DO REPLACEMATCH</A>
<LI>
<A href = "#DOREGEX">
DO REGEX</A>
<LI>
<A href = "#DOREGEXMATCH">
DO REGEXMATCH</A>
</UL>

The CryptPad program supports Command Line Automation. Commands may be placed on a command line call to automate certain editor functions. Processing numerous files by command line will be slower than you might expect because every time you start CryptPad the entire GUI will still open. This process will flash the GUI for each command line call, which will take about a second per call.

<P>
The CryptPad program changes the command line considerably from what Notepad does. I consider Notepad confusing because it opens a file from the command line but does not use the directory of the file for the Open or Save As dialog. In these dialogs it remembers the last directory used. I am not going to duplicate this confusion! There is also potential confusion about the additional feature of using a Cryptpad script.

<P>
Here is what I implemented:

<UL>
<LI>
When the CryptPad session begins it uses the current directory of the command line shell to start. Any file name with optional relative references from the command line is opened just like Notepad.

<LI>
After the file is opened, the CryptPad session current directory is changed to the directory of the opened file.

<LI>
The Open and Save As dialog will start with the CryptPad session current directory.

<LI>
When the directory is changed with the Open or Save As dialog, changing the location of the open file, it will change the CryptPad session current directory when the file is opened.

<LI>
When using a CryptPad script (only available from the command line), the CryptPad session current directory will change for the script file when opened but it will not change for file references in the script or given on the command line after the script. All relative references are to the directory of the script file.
</UL>

<P>
A single command line argument is typically a file name to edit. This allows a file to be selected for editing from the command line. A command line call is how "Open With" is supported.

<P>
There is a special mode of operation from the command line for files with an extension of .CryptPad such as "script.CryptPad". These are read as
<A href = "#DOSCRIPT">
SCRIPT</A> files for command line automation. An optional second command line argument specifies a file to edit using the script automation. This allows the same script to be used on multiple files without editing in the file name. There is no special meaning when a file with an extension of .CryptPad is used with the
<A href = "#OPEN">
Open</A> command.

<P>
CryptPad supports only one document file being specified on the command line for editing or with a script. If there is more than one command line argument (or two with a .CryptPad script file as the first argument), then the first argument must be "DO". Uppercase is not required for any automation argument. The second argument specifies the function to perform. Additional arguments specify additional information for the specific automation function to perform. The program exits immediately after most automation functions are performed. The file will be saved, if it has actually been changed.

<P>
Example command lines assuming .SAFE and .CryptPad are identified in the registry for "Open With":

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
file.safe
script.CryptPad
script.CryptPad file.safe
</PRE>
</TABLE>

<P>
Example script.CryptPad file:

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
do replace "first value" "first string"
do replace "second value" "second string"
</PRE>
</TABLE>

<P>
The standard "Open With" association does not allow an argument for the .CryptPad file. The CryptPadAdd.REG file provided in the CryptPad project contains the proper registry entries to allow an argument.

<P>
CryptPad will return an errorlevel of 0 for a successfully edited file. A value of 1 indicates that no file was saved or changed. An errorlevel of 2 indicates a command line error. Command line errors will also display an error and halt execution until the error is acknowledged. A command line or automation script error will abort saving any changes to the current file.

<P>
The following is an example Windows&nbsp7 tested CMD script which changes all files in the current directory to UTF-8 assuming the CryptPad program is in a CryptPad subdirectory of the Document directory. The CMD script displays a count of the files found and actually changed:

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
@echo off
rem
rem CryptPadx.cmd - Automation test
rem

set p=%userprofile%\Documents\CryptPad\CryptPad.exe
set /a total=0
set /a count=0

for %%f in (atest*.txt) do call :change %%f

echo Total: %total% Changed: %count%
pause

goto :EOF

:change

echo Checking %1

set /a total=total+1

%p% do utf-8 %1

echo Change error %errorlevel%

if not errorlevel 1 goto :EOF

set /a count=count+1

goto :EOF
</PRE>
</TABLE>

<P>
This is an alternate example that depends on the .CryptPad association provided by the CryptPadAdd.REG file. This method does not need to know the location of the CryptPad.exe file because it is embeddded in the registry.

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
@echo off
rem
rem CryptPadx.cmd - Automation test
rem

echo do utf-8 >script.CryptPad

set /a total=0
set /a count=0

for %%f in (atest*.txt) do call :change %%f

echo Total: %total% Changed: %count%
pause

goto :EOF

:change

echo Checking %1

set /a total=total+1

script.CryptPad %1

echo Change error %errorlevel%

if not errorlevel 1 goto :EOF

set /a count=count+1

goto :EOF
</PRE>
</TABLE>

<P>
There is a
<A href = "#Line">
Command Line</A> function from the menu of the CryptPad program to display the command line arguments provided at program startup. This is useful in debugging Command Line Automation functions.

<H3>
<A name = "DOSCRIPT">
DO SCRIPT filename</A>
</H3>

<P>
Read automation script commands from a (non-ANSI!) file. This is primarily useful to allow multiple automated replace commands. All automation script commands in the file begin with "DO". The SCRIPT command may not be used (nested) in an automation script. This command may only be used directly from the command line. It is easier to use a special "Open With" association for the .CryptPad extension as described in the CryptPadAdd.REG file.

<P>
Example script file:

<P>
<TABLE WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
do edit test.txt
do replace "first value" "first string"
do replace "second value" "second string"
</PRE>
</TABLE>

<P>
Any error will abort the automation script and return errorlevel 2.

<H3>
<A name = "DOANSI">
DO ANSI [filename]</A>
</H3>

Open the specified filename or use the existing open file. Perform the
<A href = "#ANSI">
Force ANSI</A> function. If the encoding is already ANSI, the file and its modification date will not be changed. When given as a command line, save the file, and exit. Otherwise, leave open for additional automation script processing.

<P>
Remember that a file with only ASCII characters is "UTF-8 (ASCII)" encoded. It will be saved and its modification date will be changed but the file contents will not be changed.

<H3>
<A name = "DOUTF-8">
DO UTF-8 [filename]</A>
</H3>

Open the specified filename or use the existing open file. Perform the
<A href = "#UTF8">
Force UTF-8 (ASCII)</A> function. If the encoding is already UTF-8 (ASCII), the file and its modification date will not be changed. When given as a command line, save the file, and exit. Otherwise, leave open for additional automation script processing.

<P>
Remember that a file with only ASCII characters is already "UTF-8 (ASCII)" encoded.

<H3>
<A name = "DOREADONLY">
DO READONLY file</A>
</H3>

<P>
Open the specified file read-only but do not exit and allow viewing. This allows editing read-only from the Windows Explorer context menu. The registry example file illustrates how to implement this function. This function is designed only for the command line and will abort an automation script.

<H3>
<A name = "DOEDIT">
DO EDIT file</A>
</H3>

<P>
Open the specified file. Any previously opened file will be closed and saved. This command is intended primarily for use in an automation script but will also open a file from the command line. This is the only way to open a .CryptPad file for editing from the command line. A .CryptPad file can also be opened for editing using the File, Open menu option from within the CryptPad program.

<H3>
<A name = "DOREPLACE">
DO REPLACE search-string replace-string</A>
</H3>

<P>
This command performs an automated string replace all (ignore case) function in the currently opened file. This command is only for use in an automation script.

<P>
Example:

<P>
<TABLE WIDTH = 560 WIDTH = 560 CELLPADDING = 10 BORDER>
<TR>
<TD>

<PRE>
DO EDIT test.txt
DO REPLACE "testing" "implemented"
</PRE>
</TABLE>

<P>
When a quote is part of the string it is preceded with a backslash. This function supports a subset of C-type escape character processing as described in the
<A href = "#Replace">
Replace</A> function.

<P>
<B>Warning!</B> Attempting to create a quote from a command line using an echo command to embed in an automation script does not work. In this case you may use "\q" to indicate a quote.

<H3>
<A name = "DOREPLACEMATCH">
DO REPLACEMATCH search-string replace-string</A>
</H3>

<P>
This command is similar to DO REPLACE but performs an automated string replace all (match case) function in the currently opened file. This command is only for use in an automation script.

<H3>
<A name = "DOREGEX">
DO REGEX search-string replace-string</A>
</H3>

<P>
This command is similar to DO REPLACE but performs an automated string replace all (ignore case) function using <A HREF = "#RegEx">
Regular Expression Synatx</A> in the currently opened file. This command is only for use in an automation script.

<H3>
<A name = "DOREGEXMATCH">
DO REGEXMATCH search-string replace-string</A>
</H3>

<P>
This command is similar to DO REGEX but performs an automated string replace all (match case) function in the currently opened file. This command is only for use in an automation script.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Menu">
Menu Bar Functions</A>
</H2>

<UL>
<LI>
<A href = "#File">
File Menu</A>
<LI>
<A href = "#Edit">
Edit Menu</A>
<LI>
<A href = "#Tools">
Tools Menu</A>
<LI>
<A href = "#Format">
Format Menu</A>
<LI>
<A href = "#View">
View Menu</A>
<LI>
<A href = "#Help">
Help Menu</A>
</UL>

The menu bar contains the menu groupings for all the functions performed by the CryptPad program.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "File">
File Menu</A>
</H2>

<UL>
<LI>
<A href = "#New">
New</A>
<LI>
<A href = "#Open">
Open</A>
<LI>
<A href = "#Save">
Save</A>
<LI>
<A href = "#SaveAs">
Save As</A>
<LI>
<A href = "#ANSI">
Force ANSI</A>
<LI>
<A href = "#UTF8">
Force UTF-8 (ASCII)</A>
<LI>
<A href = "#Encryption">
Encryption</A>
<LI>
<A href = "#Exit">
Exit</A>
</UL>

The file menu contains the typical functions for handling file operations, encoding, encryption, and exiting the program.

<H3>
<A name = "New">
New</A>
</H3>

A new blank and untitled document is created with this option.

<P>
If the current document has been modified, you will be offered the option to save the document.

<P>
When the window is closed, if you have made any changes, you will be offered the option to save the document to a file.

<P>
The new document will be unencrypted. You can immediately set an encryption string to encrypt the document when it is saved. You may refer to the section on
<A href = "#Encryption">
Encryption</A> for additional details.

<P>
The default encoding for the new document will be UTF-8 (ASCII). You may refer to the section on
<A href = "#Encoding">
Encoding</A> for additional details.

<H3>
<A name = "Open">
Open</A>
</H3>

<P>
Open an existing file for editing. A standard dialog is displayed to select a document file to open.

<P>
If the current document has been modified, you will be offered the option to save the document. Unlike Notepad, the document is closed immediately unless you cancel the option to save. You will not return to the document, if you cancel the Open. The encryption string of the current document is preserved for possible use in the document being opened.

<P>
If the file is encrypted with an encryption string different from the current encryption string, the encryption string will be requested. If the file is not encrypted, the current encryption string is erased.

<P>
You may refer to the section on
<A href = "#Encryption">
Encryption</A> for additional details.

<P>
CryptPad automatically detects the default ANSI code page, UTF-8, and Unicode file encodings on open. The program assumes UTF-8 encoding unless ANSI characters are detected, which UTF-8 does not read properly. It is unlikely (but possible) ANSI characters will be mistaken as UTF-8. UTF-8 without the Byte Order Mark (BOM) is identical to ASCII unless there are ANSI or Unicode characters.

<P>
You may refer to the section on
<A href = "#Encoding">
Encoding</A> for additional details.

<P>
Unlike Notepad, CryptPad maintains the file in an opened state locked against parallel changes but shared with file readers. This protects the file against accidental parallel modification data loss problems. I have had this happen to me on occasion with Notepad. You can still lose data but it will have to be by deliberate actions and not by a simple accident.

<P>
CryptPad offers to attempt to open a file read-only when any file error occurs on open. You may also specify opening read-only with the file type selection on the file open dialog. A read-only file cannot be modified and saved to protect against accidental parallel modification data loss problems. CryptPad will not ever save the file unless you use the "Save As" command.

<P>
The CryptPad program displays a warning if the file is greater than about 2MB and requires confirmation to open. The reason for the warning is that it will be very slow to edit a file greater than such a large size. Truly large files may crash the program because it reads the entire file into memory.

<P>
The CryptPad program displays a warning if a dangling CR or LF is seen outside of a CR/LF pair with a recommendation to 
<A href = "#CRLF">
Force CR/LF</A>.

<P>
The CryptPad program displays a warning if there are other non-printing ASCII/ANSI control characters (ANSI Blanks) found in the file. This also usually indicates a binary file that you really should not edit.

<P>
The CryptPad program displays a warning if NUL characters are found in the file because these must be changed to space characters for the TextBox to work. This usually indicates a binary file that you really should not edit.

<P>
Just like Notepad, a space will be substituted for any NUL characters in the file. This is required for the TextBox function. This change will not be noted as a file change to trigger a save reminder but will be included if the file is saved. This change will corrupt any binary file you may happen to save after viewing with CryptPad.

<P>
CryptPad will refuse to open a file with a backup extension of 1, 2, or 3. These will need to be renamed, if you wish to edit them.

<H3>
<A name = "Save">
Save</A>
</H3>

The current document is saved. If there is a current encryption string, the file is encrypted.

<P>
You may refer to the section on
<A href = "#Encryption">
Encryption</A> for additional details.

<P>
CryptPad uses the original file encoding when saving the file as used when the file was opened or last saved. The file contains a BOM for Unicode. UTF-8 only contains a BOM, if one was originally specified.

<P>
You may refer to the section on
<A href = "#Encoding">
Encoding</A> for additional details.

<P>
The file remains open for continued editing. You must select the "NEW" option to close the file.

<H3>
<A name = "SaveAs">
Save As</A>
</H3>

A dialog is displayed to specify a document file name to save the current document. If there is a current encryption string, the file is encrypted. The default file extension is .SAFE for encrypted text files and .TXT for all other text files.

<P>
You may refer to the section on
<A href = "#Encryption">
Encryption</A> for additional details.

<P>
CryptPad defaults to the original file encoding when saving the file. The "Save as type:" option can be used to select alternate file encodings.

<P>
You may refer to the section on
<A href = "#Encoding">
Encoding</A> for additional details.

<P>
The file remains open for continued editing. You must select the "NEW" option to close the file.

<H3>
<A name = "ANSI">
Force ANSI</A>
</H3>

Use this function to force ASCII/ANSI encoding for the current open file, if you must be certain to force ASCII/ANSI encoding when the file is written. This does not change any text currently being edited. CryptPad does not force only ASCII/ANSI text to be entered but an error will occur when the file is saved, if the text contains any Unicode characters which cannot be mapped into the current code page.

<H3>
<A name = "UTF8">
Force UTF-8 (ASCII)</A>
</H3>

Use this function to force "UTF-8 (ASCII)" encoding for the current open file, if you must be certain to force "UTF-8 (ASCII)" encoding when the file is written. This does not change any text currently being edited.

<P>
Remember that a file with only ASCII characters is already "UTF-8 (ASCII)" encoded.

<P>
You may refer to the section on
<A href = "#Encoding">
Encoding</A> for additional details.

<H3>
<A name = "Encryption">
Encryption</A>
</H3>

A dialog is displayed to add, change, or remove the encryption string. The encryption string must be at least 4 ASCII characters. Longer is better. There is no particular maximum limit. About 32 characters is an ideal choice. Only ASCII characters are allowed in the encryption string.

<P>
<B>Warning!</B> You will not be able to decrypt the contents of this file, unless you remember this encryption string. If you forget this encryption string, you will not ever be able to retrieve the encryption string. There is absolutely <B>NO</B> back door. Once you click the Ok button, you cannot remove or change the encryption string, unless you remember this string and enter it again.

<P>
You will be required to enter a new encryption string twice to verify its contents. This is necessary because you will not be able to see the contents of the encryption string as you type it. If you type the same thing twice, it is assumed there was no error and you will remember the encryption string. Make it something you will certainly remember. Since this is so highly critical, there are no particular requirements for the encryption string contents.

<P>
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 CIA high security solution!

<P>
Almost nobody will be able to break an encryption string of even a single word. A highly safe and effective encryption string is a short sentence or phrase containing at least three words. Using silly words not found in the dictionary is very effective. <B>Remember!</B> You must not forget the encryption string or you will not ever be able to decrypt your hidden data.

<P>
See
<A href = "#QuickCrypt">
QuickCrypt</A> for additional information about encrypted data.

<H3>
<A name = "Exit">
Exit</A>
</H3>

This option exits the program.

<P>
If the current document has been modified, you will be offered the option to save the document.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Edit">
Edit Menu</A>
</H2>

<UL>
<LI>
<A href = "#Undo">
Undo</A>
<LI>
<A href = "#Cut">
Cut</A>
<LI>
<A href = "#Copy">
Copy</A>
<LI>
<A href = "#Paste">
Paste</A>
<LI>
<A href = "#Delete">
Delete</A>
<LI>
<A href = "#Uppercase">
Uppercase</A>
<LI>
<A href = "#Lowercase">
Lowercase</A>
<LI>
<A href = "#Capitalize">
Initial Capital</A>
<LI>
<A href = "#Transpose">
Transpose</A>
<LI>
<A href = "#Find">
Find</A>
<LI>
<A href = "#Find Next">
Find Next</A>
<LI>
<A href = "#Find Previous">
Find Previous</A>
<LI>
<A href = "#Replace">
Replace</A>
<LI>
<A href = "#Go To">
Go To</A>
<LI>
<A href = "#Select All">
Select All</A>
<LI>
<A href = "#Date/Time">
Date/Time</A>
</UL>

The Edit Menu selection contains functions for special editing of the document.

<H3>
<A name = "Undo">
Undo</A>
</H3>

Undo the latest editing operation, if an undo is supported for the last operation. Any text you enter can be undone, restoring any optional selected text you replaced, until you use the arrow keys or the mouse to move the caret and enter new text. Only one Undo is supported by the TextBox control. A second Undo will restore the original data.

<H3>
<A name = "Cut">
Cut</A>
</H3>

Copy the currently selected text to the system clipboard and delete it from the document. If there is no selected text, the system clipboard and the document will be unchanged. You can Undo this operation but the system clipboard continues to retain a copy of the Cut text.

<P>
The text remains in the system clipboard no matter how many times you Paste until the next Cut or Copy. The system clipboard is not ever cleared, even when the CryptPad program exits.

<H3>
<A name = "Copy">
Copy</A>
</H3>

Copy the currently selected text to the system clipboard. If there is no selected text, the system clipboard will be unchanged.

<P>
The text remains in the system clipboard no matter how many times you Paste until the next Cut or Copy. The system clipboard is not ever cleared, even when the CryptPad program exits.

<H3>
<A name = "Paste">
Paste</A>
</H3>

Paste the system clipboard text to the document. This will replace any current selection. You can Undo this operation.

<P>
The text remains in the system clipboard no matter how many times you Paste until the next Cut or Copy. The system clipboard is not even cleared when the CryptPad program exits.

<H3>
<A name = "Delete">
Delete</A>
</H3>

Delete the currently selected text. If no text is selected, the character after the caret position is deleted. You can Undo this operation.

<H3>
<A name = "Uppercase">
Uppercase</A>
</H3>

Convert the currently selected text to uppercase. You can Undo this operation.

<H3>
<A name = "Lowercase">
Lowercase</A>
</H3>

Convert the currently selected text to lowercase. You can Undo this operation.

<H3>
<A name = "Capitalize">
Initial Capital</A>
</H3>

Convert the currently selected text to initial capital on the words preceded by a space. The first character of the selection is assumed to start a word. You may Double-Click on a word and type the shortcut Ctrl+I. You can Undo this operation.

<H3>
<A name = "Transpose">
Transpose</A>
</H3>

<P>
The "Transpose" function switches the character to the left and right of the caret. I don't know how often you have a problem with transposing characters as you type but it happens to me a lot. You can Undo this operation.

<P>
This function will do nothing if there is currently selected text. Nothing is done when the caret is at the beginning or end of a line. I only do the transpose for ASCII characters because of possible confusion about recognizing and parsing ANSI or Unicode characters.

<H3>
<A name = "Find">
Find</A>
</H3>

Display a dialog to specify a search pattern.

<P>
This function supports patterns that include a subset of the C-type escape characters for the ASCII control characters commonly found in text files.
The new escape characters are described in the <A href = "#Replace">Replace</A> function.

<P>
There is a RegEx checkbox to select using <A HREF = "#RegEx">
Regular Expression Synatx</A> in the search pattern.

<H3>
<A name = "Find Next">
Find Next</A>
</H3>

Find the next search pattern match in the document. If no search pattern has been previously specified, the dialog will be displayed. Unlike Notepad, this function will always search down.

<H3>
<A name = "Find Previous">
Find Previous</A>
</H3>

Find a previous search pattern match in the document. If no search pattern has been previously specified, the dialog will be displayed. This function will always search up.

<H3>
<A name = "Replace">
Replace</A>
</H3>

Display a dialog to specify search and replacement patterns.

<H4>
Escape Characters
</H4>

<P>
This function supports search and replacement patterns that include a subset of the C-type escape characters for the ASCII control characters commonly found in text files.

<UL>
<LI>
\n New line (LF)
<LI>
\r Carriage return (CR)
<LI>
\t Horizontal tab (HT)
<LI>
\\ Backslash
</UL>

<P>
If you use a single backslash in the TextBox for non-Regex patterns, it will be treated like a backslash, when it is not followed by one of the special characters. If you try to enter a search for two backslashes, it will be changed to one unless you enter four! Regex patterns will ignore the backslash if it is not followed by a special character.

<P>
The context menu and shortcuts in both the find and replace input TextBox also support the new escape characters for the Paste, Copy, and Cut functions.

<H4>
<A name = "RegEx">
Regular Expression Syntax</A>
</H4>

<P>
There is a RegEx checkbox to select using <A HREF = "#RegEx">
Regular Expression Synatx</A> in the search and replacement patterns. This is described in detail in the Microsoft <A href = "http://msdn.microsoft.com/en-us/library/hs600312(v=vs.90).aspx" target = "_blank">.NET Framework Regular Expressions</A> documentation. The <A HREF = "http://msdn.microsoft.com/en-us/library/yd1hzczs(v=vs.90).aspx#Multiline" target = "_blank">Multiline mode</A> option is automatically included.

<P>
This function is very complex and fully described in the MSDN documentation but I will supply a simple example. The search pattern:

<P>
\r([^\n])

<P>
will locate a CR not followed by LF and the replacement pattern:

<P>
\\r$1

<P>
will change the CR to "\r". The following character will get dragged into the selection since it is inspected to make sure it is not LF.

<P>
Regular Expression syntax already supports the escape characters in the search pattern but CryptPad adds their use to the replacement pattern. 

<P>
This example "Alternation Construct" uses "Conditional Matching with an Expression" to find lines that do not contain the word cat.

<P>
(?(^.*cat.*$)$|^.*$)

<P>
Be careful about the '$' in the search pattern for a replace as described in the 
<A href = "http://msdn.microsoft.com/en-us/library/h5181w5w(v=vs.90).aspx#End" target = "_blank">MSDN</A> documentation. For example, if you try to completely remove all lines that contain "cat" using the following search pattern, this will leave a dangling LF.

<P>
^.*cat.*$

<P>
Instead you can use this search pattern to correctly delete the line.

<P>
^.*cat.*\r\n

<H4>
Restore Caret Position
</H4>

<P>
The "Replace All" button on the "Replace" dialog has a special function not found in Notepad. Notepad will change the caret position to the top of the document after a "Replace All" and you will lose track of where you were editing. CryptPad remembers the current caret position line and column. CryptPad attempts to restore the caret position after the "Replace All". CryptPad even attempts to scroll the window to the same location. The caret position restore is not accurate when the "Replace All" changes the number of lines before the caret position or the number of characters on the line before the caret position.

<H3>
<A name = "Go To">
Go To</A>
</H3>

Displays the line number at the current caret position and allows you to specify a new line to change the current caret position. When Word Wrap is on the line number is of the wrapped lines, therefore it may not be the same line as when Word Wrap is off.

<P>
When you are entering a line number provided by a program, you will usually need to make sure that Word Wrap is off or you will go to the wrong line.

<H3>
<A name = "Select All">
Select All</A>
</H3>

Select all the text in the document. The text is not copied to the clipboard until you specify a Copy.

<H3>
<A name = "Date/Time">
Date/Time</A>
</H3>

Insert the date and the time in ISO 8601 standard universal date and time formats. The local time is used but the time zone is not indicated. These are separate date and time fields so they are separated with a space, as allowed by the standard. This is not to be confused with the standard format for combined date and time which is separated by a "T" character.

<P>
Example:

<P>
2013-03-24 15:55

<P>
If there is currently selected text, it will be replaced. It is assumed the selected text is an old date and time value. You can Undo this operation.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Tools">
Tools Menu</A>
</H2>

<UL>
<LI>
<A href = "#Password">
Password</A>
<LI>
<A href = "#QuickCrypt">
QuickCrypt</A>
<LI>
<A href = "#ASCII">
Find next non-ASCII</A>
<LI>
<A href = "#Long">
Find longest line</A>
<LI>
<A href = "#Ctrl">
Find next ANSI Blank</A>
<LI>
<A href = "#CRLF">
Force CR/LF (Windows)</A>
<LI>
<A href = "#LF">
Force LF (UNIX)</A>
<LI>
<A href = "#CR">
Mark dangling CR or LF</A>
<LI>
<A href = "#Wrap">
Hard Wrap</A>
<LI>
<A href = "#Unwrap">
Unwrap</A>
<LI>
<A href = "#Trim">
Trim</A>
<LI>
<A href = "#Line">
Command Line</A>
<LI>
<A href = "#Backup">
Automatic Backup</A>
</UL>

The Tools Menu contains some additional special options added by the CryptPad program.

<H3>
<A name = "Password">
Password</A>
</H3>

Insert an automatically generated random password into the document. The randomization selects 16 characters from uppercase/lowercase ASCII letters and numbers. This is particularly useful in an encrypted file for creating unique, ultra-secret, highly secure passwords for websites. Do not use this as an encryption string! It will be impossible to remember.

<P>
Example:

<P>
EHbKLQZRRv53VN5K

<P>
If there is currently selected text, it will be replaced. It is assumed the selected text is an old password. You can Undo this operation.

<P>
When you use the random password generation for websites, the sophisticated password would be stored in an encrypted file so you don't have to remember it. A typical line or sequence of lines in the encrypted file would have the website address, the email address/username, and the password. This can be used for a quick and simple copy/paste of the website address, then copy/paste the login username, and finally copy/paste the password. Unfortunately, I have discovered some difficult websites will not allow you to copy and paste the password. This is a poor security measure because you may want to paste a password you can't possibly remember or don't want to type. It is easy to delay multiple pastes to restrict password hacking.

<H3>
<A name = "QuickCrypt">
QuickCrypt</A>
</H3>

Using the current encryption string, convert the plaintext to the encrypted text. If there is not an encryption string present, one will be requested. This function is particularly useful to copy and paste encrypted text to and from email or instant messages.

<P>
You can recognize encrypted text because it always begins with the encryption prefix "~!@#$". If the encrypted text is already shown, this command will convert the encrypted text to the plaintext.

<P>
The version 1 encryption prefix was "~!@#". If you need to know, just remove character 5 ('$') and 6-13 (hexadecimal checksum) to restore version 1 compatibility.

<P>
<B>Warning!</B> If you change anything else while the encrypted text is shown, you will not be able to decrypt the text.

<P>
The encryption prefix "~!@#$" must be the first characters in the text to reverse the encryption. Version 2 has an eight hexadecimal character checksum after the encryption prefix to verify the data has not been modified or corrupted. There is also another eight hexadecimal character checksum which verifies that the current encryption string actually applies to this text.

<P>
If any encryption text is changed, in any editor, you lose the ability to ever decrypt the text. Someone who gains acces to your file can destroy your encrypted data but they can never see it.

<P>
You may refer to the section on
<A href = "#Encryption">
Encryption</A> for additional details.

<H3>
<A name = "ASCII">
Find next non-ASCII</A>
</H3>

Find and select the next non-ASCII character after the caret or current selection.

<H3>
<A name = "Long">
Find longest line</A>
</H3>

Find the first longest line and place the caret at the end of the line. This function ignores Word Wrap. Remember that the TextBox always wraps at 1024 characters so no line can be longer than this value.

<H3>
<A name = "Ctrl">
Find next ANSI Blank</A>
</H3>

The first non-printing ASCII/ANSI character found in the file will be changed to the string "\xnn" and selected. "nn" will be the hexadecimal value of the character. Values will always be "\x01", "\x1c", "\x1d", "\x1e", "\x1f", "\x81", "\x8d", "\x8f", "\x90", "\x9d", or "\xa0". These values represent characters which do not display anything so they are invisible in the typical fonts. Some of these characters display as a space and some are zero width and do not display at all.

<P>
The "\xa0" character is a No-Break Space. In an HTML file this is created with "&amp;nbsp;". If you need this in a text file it can be entered with the Alt+0160 keystroke sequence.

<H3>
<A name = "CRLF">
Force CR/LF (Windows)</A>
</H3>

First change all CR/LF to LF, change all remaining CR to LF, then make sure every LF is CR/LF. This is the normal condition for a data file used by the Windows operating systems. This is the normal editing condition.

<H3>
<A name = "LF">
Force LF (UNIX)</A>
</H3>

First change all CR/LF to LF, then change all remaining CR to LF. This is the normal condition for a data file used by UNIX type operating systems. This is not a normal editing condition. This condition is usually only created before a close and save. Some CryptPad and TextBox display and editing functions will not work correctly on a Unix file.

<H3>
<A name = "CR">
Mark dangling CR or LF</A>
</H3>

The first dangling CR or LF found in the file will be changed to the string "\r" or "\n" and selected. There will be no dangling CR or LF in a normal file. There will also be none if you responded "OK" to the warning prompt when the file is opened or after using the "Force CR/LF" tool.

<H3>
<A name = "Wrap">
Hard Wrap</A>
</H3>

Set line width permanently to the current window width by inserting CR/LF. This function does nothing unless Word Wrap is enabled. A space is left at the end of the line for possible Unwrap or Trim. It is not possible to find the end of a wrapped line with a simple replace.

<P>
When you compose paragraphs using CryptPad, Notepad, or any editor, it is helpful to have lines limited to a short width (about 60 characters) suitable for reading. Newspaper columns illustrate a very narrow width. A typical book will have a column width of about five to six inches.

<P>
When Word Wrap is on the line width will automatically adapt to the window size while removing and adding content. The Hard Wrap function is useful to change long lines with Word Wrap used while composing to short lines suitable for pasting, such as in email.

<H3>
<A name = "Unwrap">
Unwrap</A>
</H3>

Unwrap lines by removing CR/LF preceded by a space. These dangling spaces are normally created by Hard Wrap. After you use the Trim Tool, Unwrap will no longer work. This allows composing to continue removing and adding content while automatically adjusting to the window width.

<P>
This is simply a predefined replace of " \r\n" with " ".

<H3>
<A name = "Trim">
Trim</A>
</H3>

Trim any space at the beginning or end of a line. It is a tidy practice to make sure there are are no extra spaces. It is assumed that Tab, not Space, is used for indent. You may or may not choose to use Trim after a Hard Wrap. If you do, you will not be able to Unwrap.

<P>
This is simply a predefined replace of " \r\n" with "\r\n" and "\r\n " with "\r\n" .

<H3>
<A name = "Line">
Command Line</A>
</H3>

Display the starting current directory and the command line arguments provided at program startup. This is particularly useful to understand the environment of
<A href = "#Automation">
Command Line Automation</A> functions. CLA errors will automatically display this information.

<H3>
<A name = "Backup">
Automatic Backup</A>
</H3>

<P>
This menu selection allow you to select options for automatic backup. You can select anything from zero to 3 backups. When a backup is performed file.ext is renamed to file.ext.1, file.ext.1 is renamed to file.ext.2, and so on for the number of backups selected.

<P>
Backup only occurs with the first save after open. I have the practice of editing HTML in a tiled window with Internet Explorer (IE) displaying the HTML. I save the file many times while editing and refresh the IE window to see the results. I do not want a backup for every intermediate save. If you want to force a backup while editing, then you will need to open the file again.

<P>
CryptPad will refuse to open a file with a backup extension of 1, 2, or 3. These will need to be renamed, if you wish to edit them.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Format">
Format Menu</A>
</H2>

<UL>
<LI>
<A href = "#Word Wrap">
Word Wrap</A>
<LI>
<A href = "#Font">
Font</A>
<LI>
<A href = "#FontColor">
Font Color</A>
<LI>
<A href = "#Colors">
Background Color</A>
</UL>

These options change the format of how the text is displayed in the CryptPad TextBox.

<H3>
<A name = "Word Wrap">
Word Wrap</A>
</H3>

Toggle word wrap. A TextBox line longer than 1024 is always wrapped to a second display line breaking even in the middle of a word.

<P>
When Word Wrap is on, the TextBox lines will be wrapped at the width of the current window. The rules for automatic wrapping of a TextBox window are complicated. Generally, wrapping occurs at a "<A HREF = "#Word">word</A>" boundary.

<H3>
<A name = "Font">
Font</A>
</H3>

Displays a font dialog to select the font to use in displaying and editing the document. Lucida Console 12pt is the original setting.

<H3>
<A name = "FontColor">
Font Color</A>
</H3>

Displays a color dialog to select the font color to use in displaying and editing the document. Black is the original setting. I prefer a Font Color setting of Yellow on a Background Color of Blue as a very soothing high-contrast option to the boring black and white.

<H3>
<A name = "Colors">
Background Color</A>
</H3>

Displays a color dialog to pick a different background color for the TextBox during editing. White is the original setting. I prefer a Font Color setting of Yellow on a Background Color of Blue as a very soothing high-contrast option to the boring black and white.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "View">
View Menu</A>
</H2>

<UL>
<LI>
<A href = "#Status">
Line/Char</A>
<LI>
<A href = "#Before">
Before/After</A>
<LI>
<A href = "#Lines">
Lines/Chars</A>
<LI>
<A href = "#Encoding">
Encoding</A>
</UL>

This menu allows you to select what information you wish to see in the Status Bar. If none of the items are selected, the Status Bar will not be shown. If the window is not wide enough for everything to display, then only the first items that fit will display.

<H3>
<A name = "Status">
Line/Char</A>
</H3>

Toggle the display in the Status Bar of the current line number and character position of the caret in the current line. This is not necessarily the same as the column number, if there are tabs in the line. The line number can be different for the same line depending on whether Word Wrap is on or not.

<H3>
<A name = "Before">
Before/After</A>
</H3>

Toggle the display in the Status Bar of the number of characters before the caret and the number of characters after the caret.

<H3>
<A name = "Lines">
Lines/Chars</A>
</H3>

Toggle the display in the Status Bar of the total number of lines and the total number of characters in the file.

<P>
Beware! The current line number is for wrapped lines in Word Wrap mode but the total number of lines is still for real lines. Also note that the total number of characters includes the CR/LF characters and any other control characters in the text. The total number of characters will only match the file size for files with ANSI encoding or UTF-8, which contains only ASCII characters.

<H3>
<A name = "Encoding">
Encoding</A>
</H3>

Toggle the display in the Status Bar of the file encoding. Typical file encodings:

<UL>
<LI>
"Windows-1252"

<P>
Also known as "ANSI", "ISO-8859-1", and "Western European (Windows)". This is typical for many computer systems. This encoding is for the local code page which can be different on your computer depending on how the computer system is configured. ANSI characters are always 8 bits.

<P>
You will not normally see this encoding in CryptPad unless you are opening a file which contains ANSI characters or you have specified for a file to be saved with ANSI encoding.

<P>
<LI>
"UTF-8 (ASCII)"

<P>
This encoding does not use a Byte Order Mark (BOM) at the beginning of the file. This is the recommended encoding for all current files. UTF-8 characters use 8 bits but non-ASCII characters are always followed by additional 8 bit characters.

<P>
CryptPad will normally open a file with this encoding. This encoding is completely appropriate for files containing only ASCII characters and will not cause a problem creating ASCII text for any program expecting ASCII characters. This encoding will also allow you to enter Unicode characters, which will cause problems for some older programs, which expect only ASCII or ANSI.

<P>
UTF-8 characters can be mistaken for ANSI characters by an older program looking for ANSI characters. A person looking at the file contents in an editor can usually recognize immediately that the character patterns do not make sense. ANSI characters can not usually be mistaken for UTF-8 characters by a newer program looking for UTF-8 characters. UTF-8 characters follow a certain pattern.

<P>
<LI>
"Unicode (UTF-8)"

<P>
This is the same as UTF-8 (ASCII) encoding but it uses a BOM. This encoding is not appropriate for programs requiring ASCII files, even if the file contains only ASCII characters because the BOM writes non-ASCII characters to the beginning of the file. Most current programs and editors such as Notepad and CryptPad use this encoding with no problems but older programs may fail in mysterious ways.

<P>
<LI>
"Unicode"

<P>
Also known as "UTF-16". All characters in this encoding use 16 bits. This encoding is rarely used by files for Windows programs. It is important for programmers to note that most Windows programs use this format internally for all characters.

<P>
<LI>
"Unicode (Big-Endian)"

<P>
This encoding is normally only used on non-Windows computers.
</UL>

</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<H2>
<A name = "Help">
Help Menu</A>
</H2>

<UL>
<LI>
<A href = "#Online">
Online Contents</A>
<LI>
<A href = "#Contents">
Local Contents</A>
<LI>
<A href = "#About">
About CryptPad</A>
</UL>

The Help Menu contains options for viewing help and program information.

<H3>
<A name = "Online">
Online Contents</A>
</H3>

This option will open the web site "http://www.frank-t-clark.com/Professional/Papers/CryptPad/CryptPad.html" which contains the online version of the documentation for the current version of the program. This may not match the version you are using. The website is often updated with additional documentation and versions.

<P>
This web page may be saved to the "CryptPad.html" file in the directory with the program. This updates the Local Contents. Links from the page may fail unless additional pages and images are copied to the directory from the website. You will not be able to save the file if the program is installed in the "Program Files" directory unless you have administrator privilege.

<H3>
<A name = "Contents">
Local Contents</A>
</H3>

This option will open the local web file "CryptPad.html" which contains the local version of the documentation for the program. The file is expected to be in the same directory as the program file. Links from the page may fail unless additional pages and images are copied to the directory from the website.

<P>
This is useful for when you are not connected to the Internet. This help file and the minimum graphic file are included in the download zip file.

<H3>
<A name = "About">
About</A>
</H3>

This option displays the program version number and other information.
</TABLE>

<P>
<TABLE ALIGN = CENTER WIDTH = 576>
<TR>
<TD>

<HR>

Revised 2014-07-27
</TABLE>

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)

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 28 Jul 2014
Article Copyright 2013 by Frank T. Clark
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid