Code Blog


In this section I collected some small programming projects that I have developed over the recent years, some are work-related but the most are just for fun.


Password Generator

Of course there are many freely available password generator tools out there already. Even some web browsers provide this functionality to the users. Nevertheless I always wanted to have my own implementation of a password generator with my preferred set of configurations.
Check the Passgen app, a simple web application that only consists of one HTML page containing a short JavaScript.


Encryption & Decryption Mechanism

I always wanted to create my own password encryption tool. Since so-called monoalphabetic ciphers which, e.g., move every letter by the same amount of positions in an alphabet are not very difficult to break by just a simple brute-force approach, I was looking for a little more complex mechanism and one day got inspired by a TV documentary about Wold War II and the Enigma machine which was back then used by Nazi Germany to protect diplomatic and mainly military communication.
The machine makes use of a polyalphabetic substitution cipher which is based on the configuration of a set of electromechanical rotors. This way, the individual letters of an input phrase a moved different positions in the substitution alphabet and the encrypted text can only be deciphered when knowing the exact same rotor configurations that were previously used for encryption.
I adapted this approach and used a PIN to represent the mechanical rotor configurations. Since the characters of that PIN will be internally converted to their Ascii codes, it can also consist of letters rather than just numbers.
For each letter of the input phrase, the next character of the PIN (rather its Ascii code) is used to shift the letter in the substitution alphabet:

[Ascii of input letter] + [Ascii of PIN character] = [Ascii of resulting letter]

If the end of either the PIN or the substitution alphabet is reached during this process, a modulo command is used to continue again at the beginning.

The Enigma app is pure JavaScript and also optimized for smartphone usage.

Known Downside: An encrypted text will always have the same length as the input. Fell free to add some further commands to get rid of this limitation. :-)


Rectangle Drawer

I was playing around with the <canvas> element of HTML5 and created a drawer that puts a set of randomly located rectangles on the screen. Also the color is randomly chosen in a range between clear blue and violet.
Press the F5 button to generate a new set of rectangles with a glowing shadow that look somewhat like abstract art.

Screenshot of Rectangle Drawer


MP3 Tagger V1.2

A small app to remove or add ID3 tags to Mp3 files based on their file names.
With this tool you can easily remove all ID3 tags from an entire folder of Mp3 files and its subdirectories. Also, ID3 tags can be added based on the file names. Example: If all your files are named in the format "Artist - Title.mp3", these values can be automatically added as ID3 tags.

Screenshot of Mp3 Tagger

Credits: MP3 Tagger uses UltraID3Lib, an MP3 ID3 Tag Editor and MPEG Info Reader Library, copyright 2002 - 2010 Hundred Miles Software (Mitchell S. Honnert)


Add-on for NEXADIA expert

NEXADIA expert is software application distributed by B. Braun for electronic dialysis data management. The program allows the management of patient basic data, the planning of diaylsis treatments and the storage of treatment documentations.
NEXADIA expert also provides a Software Development Kit (SDK) which allows developers to extend the application with individual Add-ons. Using this SDK with C#, I developed a new area called "Medical Overview" that represents a comprehensive summary of a patient's medical data.
All information shown on the screenshot is demo data.

Screenshot of NEXADIA expert Add-on


Cellular Automaton

A cellular automaton (Wikipedia) is a two-dimensional, artificial space with physical laws which can be individually defined. A configuration which is set at the start develops in discrete and deterministic steps based on local interactions. Some configurations can move through space, reproduce or get trapped in infinite loops. Feel free to play around with different "natural laws" and draw your own starting configurations in the Cellular Automaton App.

Screenshot of Cellular Automaton


Memory V2

Version 2 of the browser-based Memory game I implemented earlier (see below in the code blog). This version has many improvements such as more card pairs, two player modes (single and multi) and a clock that records the time needed to find all pairs. On the code level, it makes use of many of the new ECMAScript 6 features.
As it only requires the jQuery library to run, it can be also downloaded and played offline on a PC, tablet or smartphone.

Screenshot of Memory


2D Color Graphs

I used the Bitmap object of the .NET framework to draw some 2D graphs with C#. The RGB color codes for every pixel are calculated by formulas that take the current x and y value as input. For example, the red component of a pixel could be calculated by r = x % 255.
By using a variety of different formulas, some very nice images could be created.

This is the core of the program code. Note that a Form must be available with a PictureBox (name = "pictureBox") on it:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ImageProcessor
{
    public partial class FormMain : Form
    {
        Bitmap bm;

        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            bm = new Bitmap(pictureBox.Width, pictureBox.Height);
            int r, g, b = 0;
            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    r = x % 255;         // Calculate red component
                    g = y % 255;         // Calculate green component
                    b = (x + y) % 255;   // Calculate blue component
                    bm.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            pictureBox.Image = bm;
        }
    }
}

Rot13

Rot13 is a simple method for encryption and decryption of texts which became mostly popular for its usage with Geo Caching. Here, hints for the location of a cache are oftentimes encrypted using Rot13, meaning that the position of a letter in the alphabet is shifted by 13 positions. Example: Position 1 in the alphabet is an A, shifted by 13 positions it becomes an N. So the word "above" becomes "nobir".
The Rot13 app is also optimized for smartphone usage.


PDF Splitter

A program to save all pages of a PDF document as individual PDF files. Texts from the contents of the pages can be used to name to result files (certain text lines can be used as variables to build the file names).

Credits: PDF Splitter uses PDFsharp, a .NET library for processing PDF.

Screenshot of PDF Splitter


7Bum

Basically a drinking game where a group of people counts from 1 onwards. Whenever a number includes the figure 7, can be divided by 7, is a repdigit, or its sum of digits is 7, the player has to shout "Bum!". If he misses to do so, he is penalized accordingly.
Find the 7bum app here.


Python Spaceship Game

A space game I implemented to get to know turtle graphics in Python. A ship is to be navigated to collide with all the asteroids flying through space in order to collect them (implementation of shooting is next on my todo list).
The spaceship is represented as a grey triangle. Use up and down keys to accelerate and decelerate, resprectively. Left and right key will change the flight direction.
Start the game by using the python game.py command.

Screenshot of Spaceship Game


Powerful PDB Web Viewer Using 3Dmol.js

Example of how to use the freely available JavaScript library 3Dmol.js to build a tailored web viewer of PDB structures. The library also allows loading other molecular file formats and creating user-defined objects.

Screenshot of PDB web viewer


Accessing PDB Header Information With Python

This code example demonstrates how PDB header information can be retrieved without importing any additional modules such as Biopython etc. The headers for the PDB codes 1atp, 3k2h, 5e8s and 4usk are downloaded and, subsequently, the title is being searched for the word "kinase". If the keyword is found, the PDB code and its corresponding title are printed.

import sys
import urllib

def get_pdb_header(pdbcode):
    f = urllib.urlopen("http://files.rcsb.org/header/" + pdbcode.upper() + ".pdb")
    lines = f.read().split("\n")
    return lines
    
def get_title_from_pdb(pdbfile):
    title = ""
    firstLine = True
    for line in pdbfile:
        if line.startswith("TITLE    "):
            add = line[9:]
            add = add.strip()
            if not firstLine:
                add = add[1:]   # remove title line number
            title += add
            firstLine = False
    return title

pdbcodes = [ "1atp", "3k2h", "5e8s", "4usk" ]    

for pdb in pdbcodes:
    pdbfile = get_pdb_header(pdb)
    title = get_title_from_pdb(pdbfile)
    
    # scan title for keywords:
    if "KINASE" in title:
        print pdb + " : " + title

Using Python's Argument Parser

By using the argparse module of Python it is very easy to create command line tools that require several arguments. This example demonstrates the usage of optional, required and multiple arguments. Note that a help text is automatically shown whenever the script is called with the option -h or not enough arguments are given.

import argparse

def get_args():
    parser = argparse.ArgumentParser(description='brief description of this script.')
    parser.add_argument(
        '-s', '--system', choices=['Windows', 'Linux'], default='Windows',
        help='Operating system to generate the output for'
    )
    parser.add_argument(
        '-f', '--file', nargs='+',
        help='Name of the file(s) to processed',
        required=True
    )
    parser.add_argument(
        '-d', '--directory',
        help='Optional name of output directory'
    )
    return parser.parse_args()

args = get_args()
print 'Going to process file(s) ' + args.file + ' for OS ' + args.system
# Do your actual work here ...

Memory Browser Game

A browser-based implementation of the game "Memory" using the JavaScript library jQuery. The game also provides time measurement for finding all pairs as well as a highscore list.

Screenshot of Memory



Last update: 2024-01-11