03rd September, 2017

Vigenère cipher in Java

A Vigenère cipher written in Java.

This is a small Java program that enciphers and deciphers text using the Vigenère cipher algorithm. This program works by taking a message from a text file and enciphering / deciphering it using a custom key. Output cipher text is printed into the terminal window instead of being written to a new text file. This jar requires 3 arguments at execution: the mode (1 for encipher, and -1 for decipher), the name of the text file containing the key, and the name of the text file containing the message you want to encipher / decipher. Example usage // to encipher java -jar vigenere-cipher.jar 1 key.txt message.txt // to decipher java -jar vigenere-cipher.jar -1 key.txt message.txt Source code public static void main(String[] args) { char[] key; String plainText; ...

Read more

02nd September, 2017

XOR cipher in Java

A binary XOR stream cipher written in Java.

This is a small Java program that reads an input file byte-by-byte, XORs each byte by a key, and streams each byte to an output file. This program works by streaming data from in input file one byte at a time through a function that XORs the bits against a byte from a key - each ciphered byte is then written to an output file before reading the next byte from the input file. The input file is never loaded directly into memory, so it is possible to cipher a very large file (if you really wanted to) without flooding your system's memory. This jar requires three arguments at execution: the name of the file containing the key data, the name of the file containing the data you want to cipher against the key, and the name of the output file. Both input and key files are read as binary files, so it is possible to cipher anything against anything, for example: an mp3 file against a png file. Example usage java -jar xor...

Read more

11th August, 2017

Selection sort in Java

A selection sort algorithm in Java.

This is a follow-up to my previous Selection sort in Python post where I briefly outlined the selection sort algorithm and wrote an implementation using the Python programming language. Selection sort is much faster compared to bubble sort; I decided to recreate the algorithm in Java to take advantage of the language's superior speed / performance compared to Python. Speed tests I have tested this selection sort algorithm to time how long it takes to sort 100, 1000, and 10,000 unsorted random numbers between 0 and 1000. Each test was run 3 times (to find the average) using a 2016 MacBook air with a 1.6GHz CPU and 4GB of RAM. All results are recorded in milliseconds, and averages are rounded to 1 decimal place. 100 elements: test 1: 0ms test 2: 0ms test 3: 0ms average: 0ms 1,000 elements: test...

Read more

11th August, 2017

Bubble sort in Java

A bubble sort algorithm in Java.

This is a follow-up to my previous Bubble sort in Python post where I briefly outlined the bubble sort algorithm and wrote an implementation using the Python programming language. The speed tests in my previous bubble sort post are pretty appalling - and this is mostly because bubble sort is a hideously slow and inefficient method of sorting numbers. However, another factor affecting these speeds is the Python interpreter itself; Python is an interpreted language and it therefore inherently slow compared to languages that are compiled down to byte code or machine code. It is for this reason I decided to re-create bubble sort in Java - to compare speeds and to introduce myself to the language. Speed tests I have tested this bubble sort algorithm to time how long it takes to sort 100, 1000, and 10,000 unsorted random numbers between 0 and 1000. Each test was run 3 times (t...

Read more

01st June, 2017

Generating inverted indexes in Python

Generating inverted indexes from text files in Python 3.6.

You can find this project on my GitHub by clicking here. This program constructs an inverted index from the words contained within a series of text files; the index is generated in memory and them saved to disk immediately. The index is constructed in a way where all files associated with a word are contained within a single text file; in other words, each word has its own text file - each text file contains a JSON string object, which contains a list of objects, which each contain which file contained the word and how many times the word occurred. Word file structure The word "hello" found in files: file_1.txt and file_2.txt {"hello": [{"file_name": "file_1.txt", "occurrences": 6}, {"file_name": "file_2.txt", "occurrences": 2}]} ...

Read more

01st May, 2017

Hiding messages inside images in Python

A program that takes messages and stores them using the pixels of an image, written in Python 3.5.

This program takes text messages and stores them inside images by manipulating the RGB channels of pixels. You can find this project on my GitHub by clicking here. Most colour images use 24 bit RGB to store and display the colour values for every pixel - each pixel has three 8 bit channels (one for red, one for blue, and one for green) meaning each channel is capable of representing a value between 0 and 255, and each individual pixel has a total of 24 bits. If we converted a 24 bit pixel to denary we would see a value like 255, 255, 255 (which is absolute white) or 0, 0, 0 (which is absolute black). Similarly, if we converted a pixel to hexadecimal we would see a value like 0xFFFFFF (which is also absolute white) or 0x000000 (w...

Read more

15th April, 2017

Selection sort in Python

A selection sort algorithm in Python 3.5.

This is a simple script that sorts lists (of arbitrary lengths) of unsorted numbers from lowest to highest. https://en.wikipedia.org/wiki/Selection_sort. Selection sort is a very simple sorting algorithm that works by iterating over all elements in an unsorted list and finding the smallest value for each iteration - the smallest value is then pushed to the beginning of the list. This process continues until all elements have been selected and moved to their correct position at the beginning of the list. Sorting elements in this way means all elements are sorted in order - the smallest elements are sorted first, and largest elements are sorted last. The worst-case performance and complexity of the selection sort algorithm can be described by the following Big O notation equation: O(n^2). Selection sort is gener...

Read more

13th April, 2017

Bubble sort in Python

A bubble sort algorithm in Python 3.5.

This is a simple script that sorts lists (of arbitrary lengths) of unsorted numbers from lowest to highest. https://en.wikipedia.org/wiki/Bubble_sort. Bubble sort is a very simple sorting algorithm that works by iterating over all elements in an unsorted list and comparing the current element to the element to its immediate right - if the element to the right is greater than the current element, swap both elements. This process continues until no more swaps occur - meaning all elements must be sorted. Sorting numbers in this way causes the largest numbers to be sorted first; bubble sort causes the largest numbers to all “bubble” up the top of the list - which is where the name comes from. The worst-case performance and complexity of the bubble sort algorithm can be described by the following Big O notation equation: O(n...

Read more

20th March, 2017

ROT13 web proxy

A web proxy that uses ROT13 to cipher data.

wsantos.io/p is a web proxy that remotely fetches web pages and uses ROT13 to cipher text during transit - evading HTTP/HTTPS packet inspection since the text is obfuscated. This web proxy works by remotely fetching web pages from the URL entered into the text box; the URL is sent to the web server via AJAX encapsulated in a JSON object. Once the remote server has fetched the web page data, any character from a-z (the key is alphabetical only, so less data needs to be ciphered - improving performance) is ciphered using this ROT13 algorithm. The ciphered web page data is then sent back to the client via AJAX, encapsulated in another JSON object; the client has a small AJAX callback function which is executed when it receives the ciphered web page data from the web server. The callback function passes the ciphered web page data to a JavaScript implementa...

Read more

25th February, 2017

Rail fence ciphering in Python

A rail fence algorithm in Python 3.5.

This is a Python 3.5 script for ciphering strings using rail fence cipher. https://en.wikipedia.org/wiki/Rail_fence_cipher. You can find this project on my GitHub by clicking here. This is a Python function that uses multidimensional arrays to create a matrix at X length (the length of the string) and Y depth (the key specified) to encipher and decipher data using rail fence - a method for arranging data in a zig-zag pattern using a grid. Rail fence doesn't require a symmetric key in the same way ROT13 does; rail fence has a set matrix depth - which controls the depth / height of the zig-zag (a greater depth will result in higher obfuscation). This makes rail fence a very insecure ciphering algorithm, as it can ea...

Read more

24th February, 2017

ROT13 in Python

A simple ROT13 algorithm in Python 3.5.

This is a Python 3.5 script for ciphering strings using ROT. https://en.wikipedia.org/wiki/ROT13, https://en.wikipedia.org/wiki/Caesar_cipher. You can find this project on my GitHub by clicking here. This is a simple plug-and-play ROT function. Simply pass the cipher function a string, key, shift value, and mode (1 for encipher, and -1 for decipher) and the function will return a enciphered / deciphered string. It is possible to use any key and any shift value with this function. If a character is not found in the key, it is just added to the final output string. I am currently using this script to power the web page enciphering engine behind Read more