Click here to Skip to main content
11,721,671 members (81,291 online)
Click here to Skip to main content

Encrypting Editor Notepad Replacement

, 28 Jul 2014 CPOL 73.9K 4.6K 107
Rate this:
Please Sign up or sign in to vote.
A C# .NET 3.5 (Win7) Windows Forms Application with source code

CryptPad Version 2015.6.5

Table of Contents

Release History

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

  • Version 2015.6.5 Released
    • Corrected inability to save an empty file.
    • Revised RegEx handling.
    • Revised the old DateTimeISO class to the new ISO8601 class with some improved naming changes.
  • Version 2015.4.12 Released
    • Read a Unicode file without the BOM (Byte Order Mark).
    • Completely revised the decoding and encoding of files.
    • Added a binary pseudo-encoding for hexadecimal display.
    • Added index references to messages about unexpected file content on open.
    • A proper plain text file always ends with CR/LF or just LF. This is now enforced by CryptPad.
    • Converted the project to Visual Studio 2013 Express for the Desktop.
  • Version 2015.3.22 Released
    • Abandoned the idea of version numbers and just made the version the release date.
    • Adjusted the way I use SystemFonts.MessageBoxFont in the program.
    • Minor revisions to the REG file following Microsoft guidelines. I am still not able to reliably make changes to edit HTML files because of Microsoft version and update changes. This needs to be changed in IE.
  • Version 3.2 Released 2015-01-11
    • Revised the old AbbreviateApproximate class to the new SI class with some improvements and changes.
    • Used MessageBox style selected by user in the Windows Appearance Control Panel.
    • Minor efficiency improvements to avoid excess copies of Textbox. This is particularly useful when editing a large file.
    • Slight adjustment to Messagebox width to avoid wrapping in marginal cases.
  • Version 3.1 Released 2014-10-05:
    • Added CryptPadAddXP.REG for those stuck on an old computer.
    • Attempted adjustments for some registry changes for HTML editing observed after updates. Temporarily, only IE can change the default editor.
    • I am still using, testing, and improving the Regex implementation and documentation. Uncovered a problem where an incorrect or incomplete Regex pattern gave no error indication.
    • Entering Find or Replace after previously using Regex caused an exception.
    • Copy or Paste of a Find or Replace string that contained a Regex pattern was corrupted.
  • Version 3.0 Released 2014-07-27:
    • Corrected link case error of 'CryptPad' not 'Cryptpad' in Help, Online Contents and Help, About description.
    • Corrected an error and some lingering confusion about the current directory handling.
    • Streamlined some of the settings code and other minor code changes.
    • 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.
    • 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.

Introduction

I loved Windows Notepad! I wrote all my HTML, Jscript, CMD scripts, and much more in Notepad. It was my favorite text file editing tool for general software development purposes. It is fast and simple. So, why did I write a replacement program?

The primary purpose of the CryptPad program is to provide optional text file encryption. This is valuable for text 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 text file at save and open. There is never a decrypted version of the text file stored unless the operator specifies to remove the encryption. The text file can be stored multiple places and moved freely like any other text file, but always in encrypted form. Anyone who knows the encryption string can read the text file with this program.

You may refer to the section on Encryption for additional details.

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 text file with all the passwords in it that I use. This is also a security risk unless the text 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 text file anywhere I want. Encrypted drives are not what I need. The text file must never exist in decrypted form. Therefore I need a simple editor which opens, decrypts, edits, encrypts, and saves a text file.

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.

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.

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 claimed "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 text files with ANSI characters as Notepad and CryptPad do. Major Notepad replacement programs such as Notepad++ will support these character encodings.

CryptPad is intended to be nearly the same as Windows 7 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 and general software development work.

I also have a major problem with Notepad because it allows a problem called parallel (or concurrent, or simultaneous) update. In parallel update, you already have a text file open with edits but it goes to the background when you switch windows. Later you open the text file again forgetting that you already had it open. You make new edits and close the text 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 text file on a network share and somebody else edits the same text file!

Unlike Notepad, CryptPad maintains the text file in an opened state locked against parallel changes but shared with text file readers. This protects the text 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. CryptPad will open read-only when needed, but it will not allow the text file to be changed and saved.

Warning! I have discovered in rare cases that some network connections will not maintain the text file open/lock for very long. I do not have a clear understanding of this problem yet. It seems to happen with old file servers that also support web services. When you attempt to save and it fails, you will need to use Save As to save the text file. You are not protected against the parallel update problem.

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 Regular Expression Syntax for Find and Replace.

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.

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.

ASCII, ANSI, UTF-8

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!?

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.

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:

http://en.wikipedia.org/wiki/UTF-8

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 webpage is almost all ASCII. In most cases, you can just stop here.

You may have noticed I slipped in the acronym BOM (Byte Order Mark) and assumed you knew what it was. If you are a detail oriented person and prepared for a heavy read:

http://en.wikipedia.org/wiki/Byte_order_mark

Simply put, a BOM is 2-3 unique bytes at the beginning of the text file that indicate how a Unicode text file is encoded. Not all Unicode text files have a BOM.

The exception from simple ASCII 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.

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 character encodings. These character encodings can be very complex and plagued with limitations. Notepad refers to this as "ANSI" character 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.

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 Character Encoding for additional details.

Installing the Program

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. The paranoid hacker knows just what I mean.

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 7 or later. You can use it temporarily, anywhere, and immediately with no install, no permissions, and no problems directly from the USB flash drive.

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 text 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.

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 HTML file, an image file, and useful scripts, which can also be placed in this directory. The help HTML file is also available online and may contain additional updated information.

If you wish, "Open With" can be set to default to CryptPad for the .SAFE encrypted text 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.

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.

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 7. 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.

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.

I have had some trouble with the registry options to automatically associate CryptPad with HTML. It changes with different versions and updates of Windows and IE. It is tricky to get it correct. Usually you will need to just make the changes in IE Internet Options, Programs, HTML editing, HTML editor or whatever the current method is.

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.

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.

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.

The CryptPad program is a C# Windows Forms application compiled in Visual Studio 2013 Express for the Desktop using the .NET framework version 3.5, which is included automatically with the Windows 7 OS. The program requires nothing but the supplied source and standard Windows functionality with VS2013. There are no third-party libraries used. There is no separate DLL required or used. The program has only been well used and thoroughly tested with the Windows 7 OS.

The CryptPad program has only been used a little with the Windows 8 OS (Yuck!). Windows 8.1 was hardly any better... Maybe Windows 10?

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 may be issues with the program on these operating systems. I don't normally use Windows Vista or XP anymore so I won't be able to help you.

However, I did face a requirement where I was working on an old automation server still using Windows XP. Can you believe that some of these old servers are still using Windows 2000!? It is sad but sometimes you can't easily replace or update these old computers that are still chugging away. So, I added CryptPadAddXP.REG for those stuck on an old computer. The difference is that the "Documents" directory is named "My Documents" on Windows XP. It is little changes like this that cause major support headaches.

Using the Program

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

  1. Start the CryptPad program.
  2. Select File, Encryption
  3. Enter your encryption string and type the Enter key.
  4. Enter the same encryption string again and type the Enter key.
  5. Enter your data.
  6. Save your text file.
  7. If you open the encrypted text file in Notepad you will see "~!@#" and more nonsense characters. Close the text file without making any changes.
  8. Open the encrypted text file in CryptPad.
  9. Enter your encryption string and type the Enter key.
  10. There is your data...

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

  1. Open any text file with the CryptPad program.
  2. Select File, Encryption
  3. Enter your encryption string and type the Enter key.
  4. Enter the same encryption string again and type the Enter key.
  5. Save your text file.

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

  1. Open any encrypted text file with the CryptPad program.
  2. Enter your encryption string and type the Enter key.
  3. Select File, Encryption
  4. Enter a blank string
  5. Enter a second blank string
  6. Save your text file.

The installation and use of the CryptPad program is NOT 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.

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 7 operating system.

Warning! 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 for using the Registry Editor that were created by a knowledgeable developer.

You are invited to go the Code Project (www.codeproject.com) forum where the CryptPad program is also published to leave comments. Registration is required. Code Project is an Internet gathering place for millions of software developers.

Using the Code

I am providing the complete VS2013 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.

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.

The project directory 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.

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.

Warning! 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.

Points of Interest

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 VS2013 project. I embedded the code for the main entry point for the application inside the primary form rather than having a separate file. Getting rid of the extra file was a desirable choice for me.

Automatic Character Encoding Recognition

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. The .NET library provides all the support needed for automatic detection but doesn't tell you how to use it.

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 text file is properly encoded without character encoding errors or malformed characters. This is a reasonable assumption for any properly written program (such as Notepad and CryptPad) used to create a text file.

The CryptPad program provides limited detection of Unicode text files without BOM. The CryptPad program is designed for text files with lines of text ending with CR/LF or just LF. This expectation provides the opportunity for a simple Unicode recognition method. This is only successful when the file ends with CR/LF or just LF.

Because I use this software in a development environment it is often possible for binary characters to be accidentally written to a text file. It is also possible to accidentally open an actual binary file. The CryptPad program handles this as a hexadecimal display with a read-only limitation.

It is a design requirement for the CryptPad program to avoid any non-standard DLL requirement, avoid the Platform Invoke (P/Invoke) feature, be as simple as practical, and depend heavily on existing standard C# .NET features.

I use the LF at the end of the text file to automatically detect Unicode LE or BE without BOM. Any normal text file will end with an LF character. If a Unicode text file without BOM does not end with LF, then you will be required to manually specify the character encoding during "Open" or using "ReOpen Decoded".

These are the possible character encodings:

Binary file
This is assumed by the existence of NUL bytes not found to be Unicode. The CryptPad program provides a hexadecimal display with a read-only limitation.
Older ANSI text file for a different code page
The CryptPad program does not provide direct support for this.
Older ANSI text file assumed for the current code page
This is readily determined with high accuracy by ruling out other possibilities. The CryptPad program checks for Unicode non-BOM determined by the existence of a Unicode LF character at the end of the text file.
Typical UTF-8 (ASCII)
This is readily determined with high accuracy because of the unique characteristics of the encoding. The CryptPad program checks for ASCII Unicode non-BOM determined by the existence of a Unicode LF character at the end of the text file.
UTF-8 with BOM
This is readily determined with high accuracy.
Unicode LE without BOM
This is determined by the existence of a Unicode LF character at the end of the text file.
Unicode LE with BOM
This is readily determined with high accuracy.
Unicode GE without BOM
This is determined by the existence of a Unicode LF character at the end of the text file.
Unicode GE with BOM
This is readily determined with high accuracy.

General procedure:

  • Attempt Encode for UTF-8 (ASCII non-BOM) and Unicode Byte Order Marks with exception to probable ANSI.
  • If UTF-8 (ASCII non-BOM), test for the existence of Unicode LF byte at the end of the text file.
  • If probable ANSI, test for the existence of Unicode LF byte at the end of the text file.

The first piece of necessary information is to recognize that the UTF-8 character encoding has been carefully designed for automatic detection, which makes it vastly different than the complexities and ambiguities of ANSI character encoding. It is highly unlikely (but possible) that an ANSI text 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 character encoding.

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.

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

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

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

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

string str = null;
try
{
    str = sr.ReadToEnd ();
    // Save the actual encoding for later write
    save_encoding = sr.CurrentEncoding;
}
catch
{
    // ANSI error detection
    save_encoding = null;
}
if (null == save_encoding)
{
    // use ANSI from the default code page
    save_encoding = Encoding.GetEncoding (0);
    file_stream.Position = 0;
    sr = new StreamReader (file_stream,
save_encoding);
    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,
    save_encoding);
sw.Write (str);

Simple Encryption Algorithm

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 the CryptPad program has 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.

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.

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

 

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

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

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

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

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

The CryptPad program uses an additional XOR checksum placed in the text file to verify whether the encryption string is correct when attempting to decrypt. The CryptPad program protects short encryption strings by extending them 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.

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

The CryptPad program uses 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 text 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.

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.

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 text 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.

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.

The suggestion has been made that the CryptPad program should use the File.Encrypt method. I do not want a decrypted version of the text file to ever reside on any drive for any period of time. I want to be able to carry the text file anywhere I want and use anywhere I want. CryptPad.exe can be carried with the encrypted text file (such as on a USB drive) and used anywhere to read the text file without any installation or removal and there is never a trace of the decrypted text 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.

The suggestion has also been made that the CryptPad program 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.

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.

Replacement Messagebox

The CryptPad program includes 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:

  • The MessageBox dialog must center on the CryptPad window rather than center on the screen.
  • 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.
  • Snap the cursor to the default button.
  • The class is a single file generic drop into any application.
  • Keep It Simple!

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

Old Style Main Menu

One of the things that make my code a little unusual is the use of the older System.Windows.Forms.MainMenu control, which Notepad uses, 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 VS2013 toolbox but is easily added to the project and still supported by the Form Designer.

In the CryptPad project, I added the following lines to the CryptPad.Designer.cs file to begin using the MainMenu control.

After the beginning of the InitializeComponent function:

private void InitializeComponent ()
{

I added:

this.mainMenu = new System.Windows.Forms.MainMenu ();
this.Menu = this.mainMenu;

At the end of the file after:

#endregion

I added:

private System.Windows.Forms.MainMenu mainMenu;

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

Automatic Font User Preference

Another of the things that makes my code a little unusual is the automatic adjustment of all dialog fonts to match user preference. First I search for and remove all font assignments so that the default is used. This causes any font change for the dialog to automatically filter down to all controls. In the constructor of all the dialogs I add the following line after the call to the InitializeComponent function:

InitializeComponent ()

I add:

this.Font = SystemFonts.MessageBoxFont;

Whatever is selected for the Message Box Font is automatically used in the dialog. It is also important to make sure the following values are uniform throughout your application:

this.AutoScaleDimensions = new System.Drawing.SizeF (6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

An additional advantage of these procedures is that the application is more robust to DPI changes from user setting or monitor changes. My experience has been that you usually achieve a readable display more easily by changing the default font (Control Panel\All Control Panel Items\Personalization\Window Color) rather than changing the DPI. Windows 8 destroyed this option. Windows 8.1 provides limited options. We will see what happens in Windows 10.

What Is Notepad?

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 edited with Notepad.

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 text file is completely loaded into memory while editing. This makes Notepad fast for the typical text file of about 64k or less. However this is a problem when editing multi-megabyte text files. The good news is that Windows 7 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.

Another important characteristic is that it supports all the standard text file character encodings. ANSI, UTF-8 (ASCII), Unicode (UTF-8), Unicode, and Unicode (Big-Endian) with or without a BOM.

What Is Windows Explorer?

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.

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.

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.

What Is Plain Text?

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.

A proper plain text file contains only printing characters designed to be read by a person. The text file will contain the ASCII CR/LF control characters to indicate the end of a line and may contain 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 text file for there to be ASCII CR or LF control characters which are not part of a CR/LF pair. A proper plain text file always ends with CR/LF or just LF. This is enforced by CryptPad when the text file is saved.

What Is the TextBox?

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.

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.

How is CryptPad different?

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 Regular Expression Syntax, and automatic backup. CryptPad provides other functionality beyond Notepad.

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 typical computer elite (geeks) 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.

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 7 but Microsoft in their great wisdom does not appear to allow us to specify our own font on Windows 8! Changing the font size on Windows 8 is also awkward, as is much of Windows 8. (Did I already say? Yuck!) Who do I complain to that will listen and do something for the handicapped or visually limited?

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.

TextBox Mouse/Keyboard Actions

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

Caret
The position in a TextBox where the next character typed on the keyboard will be inserted. This position is marked with a small blinking vertical bar. Unfortunately, particularly for those of us with less than perfect vision, it can be difficult to see this small blinking vertical bar. Sometimes you may be required to click the mouse to position the caret where you can expect to see it. I need the bar wider to be easier to see. Use "Control Panel\All Control Panel Items\Ease of Access Center\Make the computer easier to see" to change this.
Hard Newline
A Hard Newline is where you press the Enter key while entering text in the TextBox. A new line appears in the TextBox after the current line and text entry continues at the beginning of the new line. This creates a CR/LF sequence, which is saved in the text file. A Hard Newline is included in selected text and can be pasted into the document.
Soft Newline
A Soft Newline occurs when you have enabled Word Wrap and you type a letter in the TextBox that goes beyond the edge of the window. A new line appears in the TextBox after the current line and text entry continues at the beginning of the new line. This does not create a CR/LF sequence and is not saved in the text file. A Soft Newline is not included in selected text and will not be pasted into the document. There is a slight bit of confusion at the very edge of the window. If you are at the edge and type a space, the caret does not move until you type the next letter.
Pointer
The "Select" 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 called "Text Select" and is usually shaped like a tall and thin capital letter "I" known as the I-beam. Unfortunately, particularly for those of us with less than perfect vision, it can be difficult to see the default cursor. I have the same problem with all the default cursors. It is possible to select and create larger cursors. The Windows Standard (extra large) scheme works well but I pick and choose my own options and have created my own huge "Normal Select" cursor.
Word
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 hyphen "-" 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,xxxx?xx -->

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 extensive and careful testing. ANSI or Unicode definitions...?

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 extensive and careful testing.

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

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 extensive and careful testing.

Moving the Caret

Right
Move the caret one character position to the right. When you are at the end of a line the caret will move to the beginning of the next line. If there is a space at the end of the line followed by a Soft Newline the space will be ignored.
Left
Move the caret one character position to the left. When you are at the beginning of a line the caret will move to the end of the previous line. If there is a space at the end of the line followed by a Soft Newline the space will be ignored.
Up
Move the caret one line up. If the previous line is shorter than the current line the caret will move to the end of the line.
Down
Move the caret one line down. If the next line is shorter than the current line the caret will move to the end of the line.
Home
Move the caret to the beginning of the line.
End
Move the caret to the end of the line. If there is a space at the end of the line followed by a Soft Newline the space will NOT be ignored.
PageUp
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.
PageDown
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.
Ctrl+Right
Move the caret right to the start of the next word position. If this is the last word of the line, the caret will move to the beginning of the first word on the next line.
Ctrl+Left
Move the caret left to the start of the previous word. If this is the first word of the line, the caret will move to the beginning of the last word on the previous line.
Ctrl+Home
Move the caret to the very beginning of the text.
Ctrl+End
Move the caret to the very end of the text.

Selecting Text

Selected text is indicated by a change in the background color. Unfortunately, there is no visual indication if you select a Hard Newline. This can cause a little bit of confusion.

Shift+Right
Extend selection one character to the right.
Shift+Left
Extend selection one character to the left.
Shift+Down
Extend selection down one line.
Shift+Up
Extend selection up one line.
Shift+Home
Extend selection to beginning of line.
Shift+End
Extend selection to end of line.
Shift+PageUp
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.
Shift+PageDown
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.
Shift+Ctrl+Right
Extend selection to next word.
Shift+Ctrl+Left
Extend selection to previous word.
Shift+Ctrl+Home
Extend selection to the very top of text.
Shift+Ctrl+End
Extend selection to the very bottom of text.

Cut, Paste, and Undo

Ctrl+C, or Ctrl+Ins
Copy selected text into the clipboard.
Ctrl+V, or Shift+Ins
Paste selected text from the clipboard. When the clipboard is pasted into the document it will be indicated as selected text.
Ctrl+X, or Shift+Del
Cut selected text into the clipboard.
Ctrl+Z
Undo last edit. The undo is indicated as selected text.

Deleting Text

Del
Delete the character right of the caret or the current selection.
Backspace, or Ctrl-H
Delete the character left of the caret or the current selection.
Ctrl+Del
Delete to the end of the line or the current selection.

Inserting Text

Any ASCII graphic character
Insert the character typed at the caret location.
Enter, Ctrl-M, Ctrl-J
Insert CR/LF at the caret location and begin a new line.
TAB, or Ctrl+I
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.

CryptPad Keyboard Shortcuts

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

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

 

Main Menu Functions

The Main Menu contains the menu groupings for all the functions performed by the CryptPad program.

File Menu

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

New

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

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

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

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 Encryption for additional details.

The default character encoding for the new document will be UTF-8 (ASCII). You may refer to the section on Character Encoding for additional details.

Open

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

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.

Encryption

The encryption string of the current document is preserved for possible use in the document being opened. If the text file is encrypted with an encryption string different from the current encryption string, the encryption string will be requested. If the text file is not encrypted, the current encryption string is erased.

You may refer to the section on Encryption for additional details.

Parallel Update Protection

Unlike Notepad, CryptPad maintains the text file in an opened state locked against parallel changes but shared with text file readers. This protects the text 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.

CryptPad offers to attempt to open a text file read-only when any text 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 text file cannot be modified and saved to protect against accidental parallel modification data loss problems. CryptPad will not ever save the text file unless you use the "Save As" command.

File Size Warning

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

Character Encoding Options

CryptPad automatically detects the default ANSI code page, UTF-8, and Unicode with BOM text file character encodings on open. The program assumes UTF-8 character 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.

When the text file is a non-BOM character encoding, it will be tested for a Unicode LF at the end of the text file. CryptPad will attempt Unicode character encoding, if a Unicode LF is found at the end of the text file. A proper plain text file always ends with CR/LF or just LF. This is enforced by CryptPad when the text file is saved.

If NUL bytes are found with a non-Unicode character encoding, the file is marked with an Character Encoding of Binary and set to read-only.

CryptPad allows you to force the character encoding to your specification during the open. Encoding errors and NUL bytes will be ignored and replaced, when you force the character encoding.

You may refer to the section on Character Encoding for additional details.

Unexpected File Content Warnings

The CryptPad program displays a warning if a dangling CR or LF is seen outside of a CR/LF pair with a recommendation to Force CR/LF.

The CryptPad program displays a warning if there are other non-printing ASCII/ANSI control characters (ANSI Blanks) found in the text file.

The CryptPad program displays a warning if NUL characters are found in a non-binary text file because these must be changed to space characters for the TextBox to work. This is the same thing Notepad does.

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

Save

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

You may refer to the section on Encryption for additional details.

CryptPad uses the current text file character encoding when saving the text file. A proper plain text file always ends with CR/LF or just LF. This is enforced by CryptPad when the text file is saved.

You may refer to the section on Character Encoding for additional details.

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

Save As

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

You may refer to the section on Encryption for additional details.

CryptPad uses the current text file character encoding when saving the text file. The "Save as type:" option can be used to select alternate text file character encodings.

You may refer to the section on Character Encoding for additional details.

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

ReOpen Encoded

These options will re-open and re-read the currently open text file, forcing a specified character encoding. This can also be done during the "Open". This will always work but you may get garbage characters if this is not the correct character encoding.

You may refer to the section on Character Encoding for additional details.

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

Binary

Use this function to re-open the currently open text file forcing Binary character encoding. The contents will be read-only and displayed in hexadecimal. This is useful to examine the detailed results of the character encoding.

ANSI

Use this function to re-open the currently open text file forcing ASCII/ANSI character encoding.

UTF-8 (ASCII)

Use this function to re-open the currently open text file forcing UTF-8 character encoding.

Unicode

Use this function to re-open the currently open text file forcing "Unicode" UTF-16 character encoding.

Unicode (Big-Endian)

Use this function to re-open the currently open text file forcing "Unicode (Big-Endian)" UTF-16 character encoding.

Force Encoding

These options will force a specified character encoding for the currently open text file, if you must be certain to force the character encoding when the text file is written. This change can also be made during "Save As". This does not change any text currently being edited.

You may refer to the section on Character Encoding for additional details.

ANSI

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

UTF-8 (ASCII)

Use this function to force "UTF-8 (ASCII)" character encoding for the currently open text file. Remember that a text file with only ASCII characters is already "UTF-8 (ASCII)" encoded. This is the preferred character encoding format for all text files.

Unicode (UTF-8)

Use this function to force "Unicode (UTF-8)" character encoding with a BOM for the currently open text file.

Unicode

Use this function to force "Unicode" UTF-16 character encoding without a BOM for the currently open text file.

Unicode (BOM)

Use this function to force "Unicode (BOM)" UTF-16 character encoding with a BOM for the currently open text file.

Unicode (Big-Endian)

Use this function to force "Unicode (Big-Endian)" UTF-16 character encoding without a BOM for the currently open text file.

Unicode (Big-Endian BOM)

Use this function to force "Unicode (Big-Endian BOM)" UTF-16 character encoding with a BOM for the currently open text file.

Encryption

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.

Warning! You will not be able to decrypt the contents of this text 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 NO 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.

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.

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!

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. Remember! You must not forget the encryption string or you will not ever be able to decrypt your hidden data.

See QuickCrypt for additional information about encrypted data.

Exit

This option exits the program.

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

Edit Menu

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

Undo

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.

Cut

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.

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.

Copy

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

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.

Paste

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

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.

Delete

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

Uppercase

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

Lowercase

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

Initial Capital

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.

Transpose

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.

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. The CryptPad program only does the transpose for ASCII characters because of possible confusion about recognizing and parsing ANSI or Unicode characters.

Find

Display a dialog to specify a search pattern. Details about search patterns are described in the Replace function.

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 Replace function.

There is a RegEx checkbox to select using Regular Expression Syntax in the search pattern.

Find Next

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.

Find Previous

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.

Replace

Display a dialog to specify search and replacement patterns. There are some details about how search patterns work that Notepad doesn't explain and CryptPad might act a little differently. When I come across these issues I will describe them for you rather than make you guess and find out on your own.

Escape Characters

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.

  • \n New line (LF)
  • \r Carriage return (CR)
  • \t Horizontal tab (HT)
  • \\ Backslash

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 error if the backslash is not followed by a correct special character.

The context menu and shortcuts in both the find and replace input TextBox support the new escape characters for the Paste, Copy, and Cut functions unless Regex is selected.

Regular Expression Syntax

There is a RegEx checkbox to select using Regular Expression Syntax in the search and replacement patterns. This is described in detail in the Microsoft .NET Framework Regular Expressions documentation. The Multiline mode option is automatically included.

This function is very complex and fully described in the MSDN documentation but I will supply some simple examples. The search pattern:

\r([^\n])

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

\\r$1

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.

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

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

(?(^.*cat.*$)$|^.*$)

Be careful about the '$' in the search pattern for a replace as described in the MSDN documentation. For example, if you try to completely remove a lines that contains "cat" using the following search pattern, this will leave a dangling LF.

^.*cat.*$

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

^.*cat.*\r\n

Warning! I have been confounded on numerous occasions when copying and pasting Regular Expressions by a pesky unwanted space at the end of the expression. This will cause some expressions to fail unexpectedly and others to behave unexpectedly.

Warning! I have also been confounded on numerous occasions when using '^' and '$' for search and replace in Regular Expressions because replace with '$' creates a dangling LF and will not search properly. This will cause some expressions to fail unexpectedly and others to behave unexpectedly. I have found it to work better to always use '\r\n' instead of '$' in search patterns used with a replace.

Restore Caret Position

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.

Go To

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.

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.

Select All

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

Date/Time

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.

Example:

2013-03-24 15:55

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.

Tools Menu

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

Password

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 text 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.

Example:

EHbKLQZRRv53VN5K

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.

When you use the random password generation for websites, the sophisticated password would be stored in an encrypted text file so you don't have to remember it. A typical line or sequence of lines in the encrypted text 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.

QuickCrypt

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.

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.

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.

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

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.

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

You may refer to the section on Encryption for additional details.

Find next non-ASCII

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

Find longest line

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.

Show next ANSI Blank

The next non-printing ASCII/ANSI character found in the text file after the caret or current selection will be changed to the string "\xnn" and selected. "nn" will be the hexadecimal value of the character. Values will always be "\x01" (space), "\x1c" (no space), "\x1d" (no space), "\x1e" (no space), "\x1f" (no space), "\x81" (no space), "\x8d" (no space), "\x8f" (no space), "\x90" (no space), "\x9d" (no space), or "\xa0" (space). 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.

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

This function ignores dangling CR and LF characters, which also display no space. They are identified by the Mark dangling CR or LF function.

Force CR/LF (Windows)

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 text file used by the Windows operating systems. This is the normal editing condition. A proper plain text file always ends with CR/LF or just LF. This is enforced by CryptPad when the text file is saved.

Force LF (UNIX)

First change all CR/LF to LF, then change all remaining CR to LF. This is the normal condition for a text 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. Many CryptPad and TextBox display and editing functions will not work correctly on a Unix text file. A proper Unix plain text file always ends with LF. This is enforced by CryptPad when the text file is converted.

Mark dangling CR or LF

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

Hard Wrap

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.

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.

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.

Unwrap

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.

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

Trim

Trim any space at the beginning or end of a line. It is a tidy practice to make sure there 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.

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

Command Line

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

Automatic Backup

This menu selection allows 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.

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 text 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 text file again.

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

Format Menu

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

Word Wrap

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.

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 "word" boundary.

Font

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

Font Color

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.

Background Color

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.

 

View Menu

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.

Line/Char

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.

Before/After

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

Lines/Chars

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

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 text files with ANSI character encoding or UTF-8, which contains only ASCII characters.

Character Encoding

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

"Binary"

When automatic character encoding recognition detects NUL "\x00" bytes in a non-Unicode file, it will assume the file is a binary file. The data is changed to a hexadecimal/ASCII display. The file editing has also been set to read-only. The column design of the hexadecimal/ASCII display works best with a Unicde monospace font such as the original setting of Lucida Console.

If you open a text file specifying the character encoding, NUL bytes will be changed to spaces without changing the character encoding to Binary. Any character encoding failure will be ignored. You may also force a re-open specifying the character encoding. This is the recommended recovery procedure for a text file with corrupted characters.

It is possible to use "Save As" for a Binary character encoding but this results in a text file containing the hexadecimal conversion, not the original file contents. This may be useful but is not likely to be what you intended. Each of the following character encoding types has a demonstration of the Binary character encoding to illustrate the results for that character encoding. The illustration demonstrates ASCII compatible characters, a unique Unicode character, and two ANSI compatible characters. The string below was pasted into a new file. The character encoding was forced and re-opened as Binary.

Unicode Č - ANSI compatible “Menu”

  • "Windows-1252"

    Also known as "ANSI", "ISO-8859-1", and "Western European (Windows)". This is typical for many older computer systems or text files when using non-ASCII characters. This character 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 8 bit values greater than 127.

    You will not normally see this character encoding in CryptPad unless you are opening a non-ASCII text file which contains ANSI characters or you have specified for a non-ASCII text file to be saved with ANSI character encoding.

    Note that the non-Windows-1252 character was changed by Windows to a compatible Windows-1252 character.

    Unicode C – ANSI compatible “Menu”

    55 6E 69 63&middot;6F 64 65 20&middot;43 20 2D 20&middot;41 4E 53 49 Unicode C - ANSI
    20 63 6F 6D&middot;70 61 74 69&middot;62 6C 65 20&middot;93 4D 65 6E  compatible &middot;Men
    75 94 0D 0A&middot;                                    u&middot;&middot;&middot;            
    
  • "UTF-8 (ASCII)"

    This character encoding is ASCII compatible because it does not use a Byte Order Mark (BOM) at the beginning of the text file. This is the recommended character encoding for all current text files. UTF-8 characters use 8 bits for non-ASCII characters but these are always specially coded pairs or clusters of 8 bit characters. The special coding method allows UTF-8 to be recognized as non-ANSI with a high reliability.

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

    UTF-8 characters are easily mistaken for ANSI characters by an older program looking for ANSI characters. A person looking at the text file contents with an ANSI decoding 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 specific patterns.

    55 6E 69 63&middot;6F 64 65 20&middot;C4 8C 20 2D&middot;20 41 4E 53 Unicode &middot;&middot; - ANS
    49 20 63 6F&middot;6D 70 61 74&middot;69 62 6C 65&middot;20 E2 80 9C I compatible &middot;&middot;&middot;
    4D 65 6E 75&middot;E2 80 9D 0D&middot;0A                      Menu&middot;&middot;&middot;&middot;&middot;       
    
  • "Unicode (UTF-8)"

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

    EF BB BF 55&middot;6E 69 63 6F&middot;64 65 20 C4&middot;8C 20 2D 20 &middot;&middot;&middot;Unicode &middot;&middot; - 
    41 4E 53 49&middot;20 63 6F 6D&middot;70 61 74 69&middot;62 6C 65 20 ANSI compatible 
    E2 80 9C 4D&middot;65 6E 75 E2&middot;80 9D 0D 0A&middot;            &middot;&middot;&middot;Menu&middot;&middot;&middot;&middot;&middot;    
    
  • "Unicode"

    Also known as "UTF-16", the text file does not begin with a BOM. All characters in this character encoding use 16 bits. This character encoding is rarely used in text files for Windows programs. It is important for programmers to note that most Windows programs use this format internally for all characters.

    55 00 6E 00&middot;69 00 63 00&middot;6F 00 64 00&middot;65 00 20 00 U&middot;n&middot;i&middot;c&middot;o&middot;d&middot;e&middot; &middot;
    0C 01 20 00&middot;2D 00 20 00&middot;41 00 4E 00&middot;53 00 49 00 &middot;&middot; &middot;-&middot; &middot;A&middot;N&middot;S&middot;I&middot;
    20 00 63 00&middot;6F 00 6D 00&middot;70 00 61 00&middot;74 00 69 00  &middot;c&middot;o&middot;m&middot;p&middot;a&middot;t&middot;i&middot;
    62 00 6C 00&middot;65 00 20 00&middot;1C 20 4D 00&middot;65 00 6E 00 b&middot;l&middot;e&middot; &middot;&middot; M&middot;e&middot;n&middot;
    75 00 1D 20&middot;0D 00 0A 00&middot;                        u&middot;&middot; &middot;&middot;&middot;&middot;        
    
  • "Unicode (BOM)"

    Also known as "UTF-16", the text file begins with a BOM. All characters in this character encoding use 16 bits. This character encoding is rarely used in text files for Windows programs.

    FF FE 55 00&middot;6E 00 69 00&middot;63 00 6F 00&middot;64 00 65 00 &middot;&middot;U&middot;n&middot;i&middot;c&middot;o&middot;d&middot;e&middot;
    20 00 0C 01&middot;20 00 2D 00&middot;20 00 41 00&middot;4E 00 53 00  &middot;&middot;&middot; &middot;-&middot; &middot;A&middot;N&middot;S&middot;
    49 00 20 00&middot;63 00 6F 00&middot;6D 00 70 00&middot;61 00 74 00 I&middot; &middot;c&middot;o&middot;m&middot;p&middot;a&middot;t&middot;
    69 00 62 00&middot;6C 00 65 00&middot;20 00 1C 20&middot;4D 00 65 00 i&middot;b&middot;l&middot;e&middot; &middot;&middot; M&middot;e&middot;
    6E 00 75 00&middot;1D 20 0D 00&middot;0A 00                   n&middot;u&middot;&middot; &middot;&middot;&middot;&middot;      
    
  • "Unicode (Big-Endian)"

    This character encoding is normally only used on text files for non-Windows computers. This character encoding does not use a BOM.

    FE FF 00 55&middot;00 6E 00 69&middot;00 63 00 6F&middot;00 64 00 65 &middot;&middot;&middot;U&middot;n&middot;i&middot;c&middot;o&middot;d&middot;e
    00 20 01 0C&middot;00 20 00 2D&middot;00 20 00 41&middot;00 4E 00 53 &middot; &middot;&middot;&middot; &middot;-&middot; &middot;A&middot;N&middot;S
    00 49 00 20&middot;00 63 00 6F&middot;00 6D 00 70&middot;00 61 00 74 &middot;I&middot; &middot;c&middot;o&middot;m&middot;p&middot;a&middot;t
    00 69 00 62&middot;00 6C 00 65&middot;00 20 20 1C&middot;00 4D 00 65 &middot;i&middot;b&middot;l&middot;e&middot;  &middot;&middot;M&middot;e
    00 6E 00 75&middot;20 1D 00 0D&middot;00 0A                   &middot;n&middot;u &middot;&middot;&middot;&middot;&middot;      
    
  • "Unicode (Big-Endian BOM)"

    This character encoding is normally only used on text files for non-Windows computers. This character encoding uses a BOM.

    FE FF 00 55&middot;00 6E 00 69&middot;00 63 00 6F&middot;00 64 00 65 &middot;&middot;&middot;U&middot;n&middot;i&middot;c&middot;o&middot;d&middot;e
    00 20 01 0C&middot;00 20 00 2D&middot;00 20 00 41&middot;00 4E 00 53 &middot; &middot;&middot;&middot; &middot;-&middot; &middot;A&middot;N&middot;S
    00 49 00 20&middot;00 63 00 6F&middot;00 6D 00 70&middot;00 61 00 74 &middot;I&middot; &middot;c&middot;o&middot;m&middot;p&middot;a&middot;t
    00 69 00 62&middot;00 6C 00 65&middot;00 20 20 1C&middot;00 4D 00 65 &middot;i&middot;b&middot;l&middot;e&middot;  &middot;&middot;M&middot;e
    00 6E 00 75&middot;20 1D 00 0D&middot;00 0A                   &middot;n&middot;u &middot;&middot;&middot;&middot;&middot;      
    

Help Menu

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

Online Contents

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.

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.

Local Contents

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.

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.

About

This option displays the program version number and other information.

Command Line Automation

The CryptPad program supports Command Line Automation. Commands may be placed on a command line call to automate certain editor functions. Processing numerous text 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.

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

Here is what the CryptPad program implements:

  • 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.
  • After the text file is opened, the CryptPad session current directory is changed to the directory of the opened text file.
  • The Open and Save As dialog will start with the CryptPad session current directory.
  • When the directory is changed with the Open or Save As dialog, changing the location of the open text file, it will change the CryptPad session current directory when the text file is opened.
  • 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 text 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.

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

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

CryptPad supports only one document text 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 text file will be saved, if it has actually been changed.

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

file.safe
script.CryptPad
script.CryptPad file.safe

Example script.CryptPad file:

do replace "first value" "first string"
do replace "second value" "second string"

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.

CryptPad will return an errorlevel of 0 for a successfully edited text file. A value of 1 indicates that no text 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 text file.

The following is an example Windows 7 tested CMD script which changes all text 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 text files found and actually changed:

@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

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 embedded in the registry.

@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

There is a Command Line function from the menu of the CryptPad program to display the command line arguments provided at program startup. This is useful for understanding and debugging Command Line Automation functions.

DO SCRIPT filename

Read automation script commands from a (non-ANSI!) text 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.

Example script file:

do edit test.txt
do replace "first value" "first string"
do replace "second value" "second string"

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

DO ANSI [filename]

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

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

DO UTF-8 [filename]

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

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

DO READONLY file

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

DO EDIT file

Open the specified text file. Any previously opened text file will be closed and saved. This command is intended primarily for use in an automation script but will also open a text 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.

DO REPLACE search-string replace-string

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

Example:

DO EDIT test.txt
DO REPLACE "testing" "implemented"

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 Replace function.

Warning! 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.

DO REPLACEMATCH search-string replace-string

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

DO REGEX search-string replace-string

This command is similar to DO REPLACE but performs an automated string replace all (ignore case) function using Regular Expression Syntax in the currently opened text file. This command is only for use in an automation script.

DO REGEXMATCH search-string replace-string

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

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.

You may also be interested in...

Comments and Discussions

 
BugException when trying to save a file as safe without a key Pin
_Nizar23-Sep-13 21:05
member_Nizar23-Sep-13 21:05 
GeneralRe: Exception when trying to save a file as safe without a key Pin
Frank T. Clark24-Sep-13 2:09
professionalFrank T. Clark24-Sep-13 2:09 
QuestionEncryption/Decryption Algorithm Pin
Muhammad_Shoaib23-Sep-13 18:56
professionalMuhammad_Shoaib23-Sep-13 18:56 
AnswerRe: Encryption/Decryption Algorithm Pin
Frank T. Clark24-Sep-13 2:08
professionalFrank T. Clark24-Sep-13 2:08 
GeneralRe: Encryption/Decryption Algorithm Pin
Rick Bassham7-Oct-13 11:26
memberRick Bassham7-Oct-13 11:26 
GeneralRe: Encryption/Decryption Algorithm Pin
Frank T. Clark7-Oct-13 12:08
professionalFrank T. Clark7-Oct-13 12:08 
SuggestionText duplication Pin
Brisingr Aerowing23-Sep-13 15:01
professionalBrisingr Aerowing23-Sep-13 15:01 
GeneralRe: Text duplication Pin
Frank T. Clark24-Sep-13 2:03
professionalFrank T. Clark24-Sep-13 2:03 
GeneralMy vote of 4 Pin
IslamHossam5-Aug-13 23:00
memberIslamHossam5-Aug-13 23:00 
GeneralRe: My vote of 4 Pin
Frank T. Clark13-Aug-13 9:08
professionalFrank T. Clark13-Aug-13 9:08 
GeneralMy vote of 5 Pin
fredatcodeproject4-Aug-13 12:03
memberfredatcodeproject4-Aug-13 12:03 
QuestionSave as RTF format? Pin
Nosa Osayamwen16-Jul-13 9:18
memberNosa Osayamwen16-Jul-13 9:18 
AnswerRe: Save as RTF format? Pin
Frank T. Clark16-Jul-13 11:05
professionalFrank T. Clark16-Jul-13 11:05 
GeneralRe: Save as RTF format? Pin
Nosa Osayamwen16-Jul-13 19:08
memberNosa Osayamwen16-Jul-13 19:08 
GeneralRe: Save as RTF format? Pin
Frank T. Clark5-Aug-13 7:03
professionalFrank T. Clark5-Aug-13 7:03 
Questionpuzzling to use Pin
BillWoodruff7-Jul-13 18:35
memberBillWoodruff7-Jul-13 18:35 
AnswerRe: puzzling to use Pin
Frank T. Clark8-Jul-13 3:46
professionalFrank T. Clark8-Jul-13 3:46 
AnswerRe: puzzling to use Pin
Frank T. Clark10-Jul-13 5:26
professionalFrank T. Clark10-Jul-13 5:26 
QuestionFile.Encrypt Pin
Frank T. Clark7-Jul-13 8:52
professionalFrank T. Clark7-Jul-13 8:52 
SuggestionUnauthorized users should not be able to modify contents Pin
Anish_Chakraborty20-Jun-13 1:25
memberAnish_Chakraborty20-Jun-13 1:25 
GeneralRe: Unauthorized users should not be able to modify contents Pin
Frank T. Clark20-Jun-13 2:54
professionalFrank T. Clark20-Jun-13 2:54 
GeneralRe: Unauthorized users should not be able to modify contents Pin
Frank T. Clark21-Jun-13 9:30
professionalFrank T. Clark21-Jun-13 9:30 
GeneralRe: Unauthorized users should not be able to modify contents Pin
Anish_Chakraborty23-Jun-13 23:12
memberAnish_Chakraborty23-Jun-13 23:12 
QuestionWhat a great article, Frank! Pin
Tom Clement16-Jun-13 5:37
mentorTom Clement16-Jun-13 5:37 
AnswerRe: What a great article, Frank! Pin
Frank T. Clark16-Jun-13 6:47
professionalFrank T. Clark16-Jun-13 6:47 

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

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

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