Enigma

An experimental encryption program in Java.

: java

Concepts Used

  • Object Oriented Programming
  • GUI using Swing
  • Crypto class in Java API

Features

  • Complete GUI
  • Basic Cypher Implentation
  • AES, TripleDES and Blowfish for text file encryption.

Code


Introduction

Enigma has a built in text editor and supports AES, TripleDES and Blowfish encryption algorithms.

This was my only and biggest Java project, we had OOP in our Sem 3 syllabus and this project was a good way to learn the concepts.It had started out as a basic gui app to encrypt text put in a text-box according to simple cyphers.

Working

Until now, I was making command line applications exclusively and I was frustrated by how ugly they looked. I used ASCII art to spruce them up, but there is only so much I could do.

Then came Java, and with it came , Swing API. Yay.

I took a book from my library and read all I could in a few days and got down to work with it.

As I understood how layouts and panels and elements etc worked and I outgrew making them from scatch. So I scrapped all the old code and started afresh using Netbeans IDE which has a GUI editor built-in.I had to write my logic and the even-listener behaviours and things got easy from there..

First I made a basic GUI app to encode and decode basic stream cyphers. This part of the project was just for getting familiar with swing and OOP concepts.

The app has 3 basic components:

App Utility GUI sections

These include:

1. A beautifully designed Intro Page

This took alot of time coz I was very picky about how it looks. There are actually 3 differnt JPanels overlapped to accomodate:

  • The base of app with custom window controls.
  • A gif of the blue flame as a background
  • The logo and the button to continue

2. Licence

An obligatory licence page , with popups to confim if you dont agree. The Licence page is scrollable and looks legal.

3. A Mode selector popup

This is used to select which mode to use.

  • Text Encryption
  • Basic Cypher

There are also sub options for the former.

4. Exit Panel

This is called when the app is exited from any window. It greets you and closes after 10 seconds . Also has a link to my project pages.

Basic Cypher Sections

There are 3 cyphers coded by me:

You can choose the cypher from a dropdown from the top of the cypher intro window. It is tabbed to change quickly.

For each, there is an input text input pane, an output pane and a place to chose and enter the key, except in Atbash.

Text File Encryption Section

There came a point when I realised how silly the cyphers looked, so I started to work on using AES , TripleDES and Blowfish algorithms.

I wanted a convenient way to encrypt text files, so I decided to make a Notepad like editor with options in the menu itself.

The encryption algorithms were provided by the java.crypto class. Since Block cyphers work on blocks of bytes, so the key was generated in the same datatype, Byte Array;

But the problem was to show this key to the user, so I decided to Base64 encoded the key to get a readable string which can then be stored as a text file. Helper methods to take care of the same were used.

The Algorithms used were:

  • AES (128 bits)
  • Blowfish (128 bits)
  • TripleDES (168 bits)

The key sizes were chosen to be convenient, yet secure for medium size text files.

Features

On executing the Jar file, you are greeted with an awesome introduction screen as shown above. The cool blur fire thingie actually moves, looks real cool :P.

There are two modes to run this application:

  1. Basic Cyper Mode: Where basic Stream Cyphers are implemented.
  2. Text File Encryption Mode: Where Block Cyphers based algorithms like AES, TripleDES and Blowfish are implemented

1. Cyper Mode (String based Stream Cyphers)

Important Concepts:

  • Stream Cyphers act on on streams of data as it is received.
  • The basic cyphers implemented here dont need the data to be of any particular size.

In this mode one can quickly encode string of data with the relevent cyphers.

Enigma supports the followingC cyyphers:

Additionally there is a One Time Pad to encrypt data quickly with a bit more secure keys.

2. Text File Encryption Mode (Block Cyphers)

Some Important Concepts:

  • Block Cyphers work on Block of data (bits)
  • Since the purpose of this project was education, even though the encryption happens at the bit level on blocks of data, I chose to display the encrypted text as a Base64 encoded string.

In this mode, we utilize the EnigmaEditor which has built in features to encrypt/decrypt any text files. It doesnt necessarily have to be a .txt file, any UTF-* encoded file will work.

It has 3 Encryption Algorithms:

Once the text is encrypted/decrypted, normal document operations like edit, save etc can be carried on.

For more details check the page for Enigma Editor.

Conclusion

This was the biggest project I had worked on till now, and due to this I could perfect OOP concepts and got good at using JAVA. Also I learned the theory for cryptography and its implementation.