Thursday 27 January 2011

Crystal v1.0 An encryting text editor.

I have been coding and developing an encrypting text editor recently after I felt the need for such an editor myself.  It protects your text file by encrypting it. It is not complicated to use and has familiar menu actions.

 Some technical details.

1. It uses TripleDES key to encrypt your data onto the disk.

2. The data on the disk i.e. the encrypted binary is in base64 encoding.

3. Built out of SUN JAVA.

Features:

1. It performs the actions of a simple text editor well.

2. Provides encryption for the data. TripleDES with a strong key is good enough and is supported by SUN Java.

3. User provides password from which the encryption key is generated.

4. Since it is purely Java it can run on multiple platforms.

5.  The data from the file can be copied on to an email text and then you can use it at the other end with Crystal and the password.

Limitations and Future features:

1. Handles only one file at version 1.0.

2. AES encryption on next version.

3. Another thought that came to my mind is that, the encryption module can be used in application to protect configuration files.

Installation:

1. Crystal is here  OR http://www.filefactory.com/file/b52f2h0/n/Crystal.jar

2. You will need SUN Java 1.6.x for this to work.

3. Since it used TripleDES you will also need unlimited encryption strength policy files from SUN website here  OR https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=jce_policy-6-oth-JPR@CDS-CDS_Developer

4. Copy the policy files to your JRE/lib/security folder. Thats it.
Hope you find this useful.

Screen shots







Sunday 16 January 2011

Bit Vector approach in Java

This is my implementation of the bit vector mentioned in programming pearls. As mentioned in the book the bit vector has execution time and space advantage.1/4th execution time to order a list of 1 million integers in my experiments compared to a quick sort. The execution time was less than a second. The code is self explanatory. May be some more optimization is possible but, this seems ok. The limitation is that, none of the integers repeat in the list plus and integer type is expected for the array index.

An example bit vector representing the numbers 8, 10, 2, 4, 7 is 0010100110100000 with the corresponding bit location set. (0 is inclusive in the list)

/**
 *
 * @author Hari
 */
public class BitVector
{
    //the array of bytes.
   byte[] bitvector;
   //this is the maximum number we expect in the range.
   int nMaxLimit;
   //byte count needed.
   int nByteCount;
   // the zero mask.
   byte byZero = 0x00;
   //byte values used to set and retireve individual bits.
...................
...................
...................
...................
...................

   // Generate the bytes used to set - reset bits in the sequence
   private void genSet()
   {
       bySets[0] = 0x01;
       for(int nIndex = 1; nIndex < 8; nIndex++)
       {
           bySets[nIndex] = (byte) (bySets[nIndex - 1] << 1);
       }//for
   }//

   // Initialize all the bits to zero.
   private void setAllToZero()
   {
       for(int nIndex = 0; nIndex< nByteCount; nIndex++)
       {
           bitvector[nIndex] &= byZero;
       }//for
   }//


   //set the nth bit in the array.
   public void setAt(int n) throws Exception
   {
...................

...................
...................
...................
...................

       locInVector = qt;
       bitvector[locInVector] |= bySets[7 - rem];
          
   }//

   // check if n is in the vector. i.e by checking the nth bit in the byte array.
   public boolean isPresent(int n) throws Exception
   {
       if(n > nMaxLimit || n < 0)
           throw new Exception("Argument outside range of bit vector.");

       int locInVector;
       int qt = n / 8;
       int rem = n % 8;

       locInVector = qt;
       if((bitvector[locInVector] & bySets[7 - rem])==0)
       {
           return false;
       }
       return true;
   }//

...................
...................
...................
...................
...................

}//class


Wednesday 12 January 2011

Alpha Rex Complete

I finally finished the Alpha rex robot. The head and hands were remaining from where I left it last time. The hands are operated using a single motor using lever, gears like lego blocks which is pretty amazing. The hands do not do much apart from being able to move as in the video.

Overall pretty impressed with what lego mindstorms came up with. Now remains using regular code rather than vpl.

The video is here
http://www.youtube.com/watch?v=9WuMRkO8lSk