## Substitution cipher tool

I was reading a textbook for my course and was challenged by the book to break a substitution cipher. A substitution cipher is an mono-alphabetic encryption scheme whereby each letter is substituted by another letter. This cipher scheme is considered weak because it is susceptible to frequency analysis attacks. For example, in English, the letter E is the most common letter, so by analysing the frequency of each letter in the cipher text, it is possible to derive some information about the encryption, in this case, the letter which is substituted by E.

Feeling relatively bored one day, I decided to make a web app to help me solve the challenge. It is pre-loaded with the cipher text from the book if anyone is interested to try but one can simply enter any cipher text in the textbox. What the app does is it provides an interactive platform for the adversary (us) to try and decipher the cipher text, using statistical information such as frequency, digrams and trigrams. To change the substitution, drag the letters in the ‘lang’ row to swap them. This will trigger a change in the decrypted message. The checkbox will cause the letter in the decrypted text to be in uppercase, to ease differentiation between probably correct letters from the rest. One can also insert spaces in the decrypted text and it can be saved by pressing the save button.

When I started building this, I only implemented the letter frequency and was matching the letters based on the frequencies. However, it wasn’t really helpful because firstly, it didn’t produce a readable text from the ciphertext, and analysing a random article on wikipedia (I used ‘philosophy’) showed that the letters could be rotated or swapped. All frequency analysis could do was to classify letters into bands of letters. So I needed something more powerful. Upon doing some research, I realised that most frequency analysis are usually accompanied by digrams and trigram analysis. That made sense because it could ‘correct’ the rotation of letters in a band. So I decided to include that in the app as well. After about an hour of playing around. I finally managed to solve the cipher text.

If you did not manage to solve it and just want the answer. The obfuscated answer is:

PELCGBTENCUVP FLFGRZF NER RKGERZRYL QVSSVPHYG GBOHVYQ ARIREGURYRFF SBE FBZR ERNFBA ZNAL ABA RKCREGF VAFVFG BA QRFVTAVAT ARJ RAPELCGVBA FPURZRF GUNG FRRZ GB GURZ GB OR ZBER FRPHER GUNA NAL BGURE FPURZR BA RNEGU GUR HASBEGHANGR GEHGU UBJRIRE VF GUNG FHPU FPURZRF NER HFHNYYL GEVIVNY GB OERNX

More code to break:

http://www-math.ucdenver.edu/~wcherowi/courses/m5410/exsubcip.html

CK PKHG VG CKUGZ QAG CKUGCLGPQ FJZ IGPQ QAFQ QLHG FJZ EFQG KE FCC QAGLO ULJQFRG MOGPQ AFUG ZOSJB QAGLO TSM FOKSJZ KO QVK IGEKOG FJZ KJG IX KJG TOGMQ PLCGJQCX QK OGPQ YD

## Some cool webapp technology

Right after my exams, I took up a project with a friend to create a phone app. It was my first app made and I was quite satisfied with it. The app is meant to be a companion app to my college’s May Ball. The requirements was that it displayed the programmes and a reminder feature, have a map of the place, and the ability to share photos. I shall discuss some of the technologies used.

## PhoneGap

My friend and I both had more experience with web programming than with phone programming so we decided to go with phonegap. PhoneGap allows the creation of mobile phone app using standardized web API. If the web app uses only the native API provided, it can also be deployed online into the different platforms such as Android, iOS, Windows, etc. However, custom plug-ins that hacks the phone native API won’t work with the online method, and they have to be compiled separately. There is a library of plugin here but some of them are meant for earlier versions and might have compatibility issues with the latest version. This was the main problem I faced when developing this app. I wanted to create a local notification on the phone at a certain time, however, that could only be done with an external plugin made for earlier versions of PhoneGap. It took me awhile to fix issue. On the bright side, I learned a little about the structure of the phone apps.

## Parse.com

The original plan was to store the data online using parse.com which offers hassle free online data storage. They provide push service as well, which was pretty cool. Unfortunately, I found it quite hard to manipulate the image data that I wanted to store. So I ended up using a simple MySQL and PHP script instead, which I am more comfortable with. Nonetheless, this is a pretty cool technology worth looking into. An example of a simple web app using parse is this todo list.

## TileMill + Leaflet

This two technologies allow the creation of responsive map. The original plan was to display the map in the in-app browser and use js plugins (hammer.js) to resize and pan. But that proved to be quite challenging and it was also rather jerky, so we decided to use tiling instead.

## iScroll

This provided a nice user interface, providing bouncing off the edges. However, on my version of android, it faced some problems with text inputs. This is because this plug in overwrites the default action of everything (changes the focus) to achieve the scroll effect. The solution is to alter the code such that it ignores text inputs, so that the original action for text inputs is retained.

It’s a pretty straightforward and simple app. But I’ve learned a lot during this journey, I hope to be able to create some useful apps soon.

## My current phone build

It is wise to re-install the ROM of android phones once in a while – doing this will not only remove unnecessary clutter that slows the phone down, it also provide new features that come with updates. I have been harbouring this though of installing a new ROM for some time, since the start of the year actually, but have always been busy with other things. Today I finally found the time to do it, and it took me a good 3/4 of a day.

This post is mainly to log my process for future reference. It contains links to resources as well as some app recommendation that is useful to readers. This is by no means a complete walk-through of how to install a custom ROM, I would recommend google and xda forum for that. This is more of an outline of a possible phone build and how I use my phone.

## Starting point

I remember installing a custom rom (HTC revolution HD) on my HTC sensation XE about a year and a half ago from this website. I went back to the same website to see what are the latest ROMs available and was quite excited to see ROMs with the new android version. I initially installed Codename Lungo but then encountered some problems with the search key – it doesn’t launch google search, and it was also missing some default useful apps such as torch and calculator, which can be useful at times. So I decided to install CM10.1 AOSP instead. Both ROMs gave my device a new breath of life. The previously slow and unresponsive phone has transformed into a very modern and responsive phone. I was very pleased. To me, speed is the utmost importance and phone features come second since I only use my phone for a very limited purpose and I just want it to do those functions well. The ROM exceed my expectation by giving it a very nice UI (credit goes to the new JellyBean android version).

## The selection

After using my phone for a year and testing different apps along the way, my phone has chalk up some random junk in the memory. In exchange, I know what apps I must have and what apps I can do without. A good rule of thumb is if I can’t name or describe the app without looking at my phone, I probably won’t use it again.

My main criteria for apps are:

Cross platform

My workflow involves rotating between my computer, tablet, and phone and I want to be able to access my data on all platforms without any unnecessary hassle. This is also precisely the reason why I looked into tiddlyWiki in the past.

Works offline

I do not have a data plan so I cannot rely on apps that requires the internet to function. Due to the lack of wireless connection in my room, I set up wireless hotspot with my computer for my other devices to connect to. I want my devices to be in sync when they are connected to this network.

Effortless synchronisation

It is not difficult to manually ensure that files are up-to-date but the human memory is not to be trusted with such task. The third criteria is that updated data should be accessible across devices. While there are cloud storage services like dropbox and its likes around, I feel uneasy uploading huge amount of data to be synchronised over the internet – for security and speed reasons.

## The necessities

I’ve filtered the list of apps that I needed to the following:

An offline dictionary which does translation to other languages as well. I took up learning German and French over the past year and this dictionary has served me very well.

* HanPing – A mandarin dictionary which can detect handwriting

* WikiDroyd (replaced now by aard)

An offline version of wikipedia (and other encyclopedia). Knowledge is power and wikipedia is the best source of free information.

* Epistle (replaced now by draft) – A text editor that can synchronise with dropbox

I like to take notes – I take notes when I read a book, visit museum, contemplate over life. This is my digital pen and paper. The physical pen and paper suffers the risk of damage and getting lost and also the lack of searchability but this solves all these problem. The best thing is it is lightweight since it’s just text and it synchronises smoothly with dropbox, making my notes accessible across all devices. Using a markup language like Markdown is an option to record notes.

* SweetHome wifi – A tool to synchronise photos with the computer over wifi automatically

Occasionally, I take photographs with my phone. However, over the past few years I realised I am very disorganised with the photos taken. I can never be sure whether the photos in my phone has already been transferred and kept on my computer or not. This app solves the problem by synchronising my photo album with a folder on my computer automatically every time I connect to a selected network (in this case my wifi hot spot). It has been working great and I can seamlessly access photos I’ve taken on my computer without bothering with connecting the phone to the computer and switching to USB mode.

* Draw – A simple blackboard to allow drawing

* Detexify – An app that converts handrawn symbols to latex

* AndTidWiki – An offline tiddywiki reader

* Memoires – A dairy to record significant events

An app to access phone data via a computer. This app makes it easy for me to access my files and clipboard. I’ve used it mainly to access and modify the clipboard when I’m in my room, it can also be used outside of my room as long as the computer that access it is connected to the same wifi network.

* K-9 Mail – An app to get my mail across multiple accounts

* Opera Mini – Internet browser that is fast and supports sync

* Dolphin browser – Another good internet browser. I compartmentalise my internet surfing so I use two browsers.

My favourite keyboard replacement. It predicts words well, allows multiple words prediction, and also a swipe-to-delete-word function which is nifty. I think the way to type fast in the phone world is to delete the whole word and retyping it rather than by locating the error by using our oversized thumb or index figure or by using auto correct like with iOS.

* SyncMe – Another app to synchronise the phone and the computer. This is used to synchronise other folders.

Boldface apps are those that I use almost every time I use my phone and I would recommend it to people.

## The fluff

Next come some system tweaks and apps that are good to have, often existing without me knowing.

* CamScanner – take picture of documents
* AnkiDroid – Flash card app (cross platform)
* Cipher tools – useful tool to decipher text
* ConnectBot – SSH terminal
* Soundhound – A song recognition app
* Dropbox and Boxcryptor – Cloud storage and encryption tool

## Some debugging

As with most hacks, things rarely work out of the box. I encountered some problems here which I subsequently solved.

Unable to install app because there is not enough space

This occurs when you install an app but it says there is not enough space even though there is clearly enough space when one checks the storage. This can be solved by using a file manager and deleting the file associated with the app found in /data/app.

Unable to get into recovery using adb

I don’t really know why this is happening (probably a different driver is needed). But there is an option called advanced reboot which allows the phone to reboot into recovery without adb. Need to activate developer mode by going to “about phone” and continuously pressing build number.

Final words

I am extremely happy with my new phone, it’s like a modern phone in a body of an old phone. I realised I didn’t elaborate as much as I intended to so I’ll probably do that next time if I feel like it.