home

Text Encrypter Update

After a year I've decided to update my text encrypter! Yep, it's been a year already, time flies.

What's new?

I've rewritten the encryption bit to be much more secure! The key is now 'salted' and hashed before being used to encrypt the text. A random initial vector is also created for the base of the encryption. The random salt and vector are placed in the output along with the encrypted text. In the future the salt could be placed along with the program but it would mean that it could only be decrypted by one machine. (installation of the program)

On a side note, the length of the key is 128 bits as you would need to download an update to remove the limitation on the key size in Java. (And be able to encrypt using 192 or 256 bits keys.) I've finally fixed a few small bugs concerning saving new files and accessing other drives. No other major changes in the GUI or the behaviour of the software.

Your old files will not be compatible with the new version! You will need to decrypt them with the 0.1 and re-encrypt them with the new 0.2 version.

Download

Here is the new zip file: TextEncrypter.0.2.zip

Playing with canvas

I had a lot of fun the last few days while playing with the canvas element and now is the time to present the script I came up with.

Waves !

To test a few of the functionalities provided with the canvas I've decided to create a background generator. Currently, it generates multiple waves and you can set a few things like the number of oscillations or the shadow effect. Before going in details, I invite you to go a test it right away: The Wallpaper Generator
As you can see, this generator is limited in generating waves. In the future I may implement more generators as listed in the menu.

{ how }

I'll be mostly explaining and showing the Javascript code for this WebApp, I'm assuming you already know some HTML and the main thing you will need is a canvas element:
You may also want to set a default size and an id to it:

Resizing the Canvas

Sadly the styling of the element won't be enough to resize the canvas. In the app I'm not really resizing the element, I'm just recreating a new canvas with the desired dimensions. This requires the canvas to be contained in a parent we can refer to in our script, I'll be using #canvas-cont as the parent id.
function generate(){
	// getting the size from the inputs
	var sizex = parseInt($("#sizex").val(),10);
	var sizey = parseInt($("#sizey").val(),10);
	
	// replacing the canvas with a new one
	$("#canvas-cont").html('');
	
	// redefining the main variables
	canvas = document.getElementById("canvas");
	ctx = window.canvas.getContext("2d");
	height = sizey;
	width = sizex;
}

Randomizing

To get interesting outputs I've decided to be able to randomize some inputs. As you can see you can manage the randomness of certain inputs by setting an interval. Here's two Javascript functions I've made to generate random umbers (and also an unused function to set the drawing to a random colour):
function rdm(min, max){
	return ((Math.random()*(max-min))+min);
}

function rdmint(min, max){
	return Math.floor((Math.random()*(max+1-min))+min);
}

function rdmColor(){
	ctx.fillStyle = "rgb("+rdmint(0,255)+","+rdmint(0,255)+","+rdmint(0,255)+")";
}

The Waves

I've created a general function to draw a wave:
function wave(ys,nb,ht){
	ctx.beginPath();
	for(var x=0;x<=width;x++){
		var y=Math.sin(x*nb*Math.PI*2/width)*ht+ys;
		ctx.lineTo(x,y);
	}
	ctx.lineTo(width,Math.sin(x*nb*Math.PI*2/width)*ht+ys);
	ctx.lineTo(width,height);
	ctx.lineTo(0,height);
	ctx.lineTo(0,width,y);
	
	ctx.fill();
}
The function takes 3 arguments. ys is where the wave should start on the y axis, nb is the number of waves you will have and ht is the height of the waves.
After drawing the wave, we finish the shape which will fill the bottom part of the canvas with the same colour.

On the Side

In order to create this WebApp I've used Bootsrap and a few plugins with jQuery. I'm using Slider for Boostrap and Colorpicker for Bootstrap allowing user-friendly inputs.

Bazinga Bot

Bazinga Bot (@bazingbot) is a bot I've developed last month, it should be online soon.

What is it?

Bazinga bot is a bot tweeting automatically to users saying 'Bazinga' on twitter. It will find the new post containing this word and reply with a catchphrase. It also replies, if you tweet him, with quotes from Sheldon (from the Big Bang Theory if you haven't guessed). Quotes will be added when new episodes comes out.

Under the hood

This bot was codded using Python and Twython, a library to use the twitter api with Python. In the fututre, it will run every few minutes on a Raspberry Pi or on this website. (The truth is, I wanted to find something interesting to do with my raspberry Pi.)
The bot will also search for 'opt out' words when users tweet to him, it will then add these users in an 'opt out' user list and will not annoy them again. Some of these words are 'Stop' or 'Shut'. The user can then 'opt in' again with tweets containing 'come back' for example.
This bot is meant to be fun, but some people might find it annoying, that's why I've added the opt-out feature.

Example

Text Encrypter

Here is what I've been developing the last few weeks:
Text Encrypter is a free tool that allows you to create and encode text. The purpose is to be able to protect sensitive data as passwords or over profile information. Feel free to protect any data you want.

The encryption uses the AES algorithm and the key is encoded in Sha-1 before being used.

Download

This program is at an early stage and may not be stable, but you can still download it here: TextEncrypter.0.1.zip

About

This program has been developed in Java and uses the icons available at famfamfam.com . To run it you must have version 1.6 of Java or higher.

Some of the code

While developing this app I made some interesting classes you may want to use in your own projects. One of them is a custom TextField class that allows me to have a placeholder. Simple and small, there it is:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.Graphics2D;
 
import javax.swing.JTextField;
 
public class JTextFieldPlaceHolder extends JTextField{
    private String placeHolder;
     
    private Color textColor = Color.BLACK;
    private Color placeHolderColor = Color.GRAY;
     
    JTextFieldPlaceHolder(){
        this("", "");
    }
     
    JTextFieldPlaceHolder(String placeHolderInit){
        this(placeHolderInit, "");
    }
     
    JTextFieldPlaceHolder(String placeHolderInit, String value){
        super(value);
         
        this.setMargin(new Insets(0,5,0,5));            // We set the margin so the text doesn't stick to the textField
        this.setMinimumSize(new Dimension(70, 35));     // We set a minimum size so that the textField doesn't end up crushed in small containers
         
        placeHolder = placeHolderInit;                  // We set the placeHolder variable
         
        this.setForeground(textColor);                  // We finally set the color of the text
    }
     
    // We override the paint method to draw the placeHolder when needed
    public void paint(Graphics g)
    {
        super.paint(g);
         
        // if the textField is empty
        if(this.getText().equals("")){
            Graphics2D g2d = (Graphics2D)g;             // Cast g into Graphics2D to be able to draw smooth text
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
            g2d.setFont(this.getFont());                // Set the font into the textField font
            g2d.setColor(placeHolderColor);             // Set the font color, then draw the text
            g2d.drawString(placeHolder, 7, (this.getHeight()/2)+(this.getFont().getSize()/2)-1);
        }
    }
     
    public String getPlaceHolder(){
        return this.placeHolder;
    }
     
    public void setPlaceHolder(String newPlaceHolder){
        this.placeHolder = newPlaceHolder;
    }
     
    public Color getPlaceHolderColor(){
        return this.placeHolderColor;
    }
     
    public void setPlaceHolderColor(Color newPlaceHolderColor){
        this.placeHolderColor = newPlaceHolderColor;
    }
}
Here’s an example:
JTextField myinput = new JTextFieldPlaceHolder("PlaceHolder","InitialValue");
JTextField myinput2 = new JTextFieldPlaceHolder("PlaceHolder");
JTextField myinput3 = new JTextFieldPlaceHolder();
More source code will be available soon.
1