Tuesday, November 24, 2015

Steps to get license for Desktop Alarm Clock

To get a license key for the Desktop Alarm Clock,

1. Email dhiviyadhanasekar@gmail.com, requesting for author's bank account details. Email subject should be "Desktop Alarm Clock - License Request".

2. Once you receive an email with bank account details, transfer the amount specified in the email to the bank account and email back with the transaction reference.

3. Once the transaction has completed, author will email you back the the user name and license key.


Note: The above was done to hack the payment link on an application that I reverse engineered and by pass the registration process by reverse engineering the application using OllyDbg and creating a patch, that would exploit the application's security\vulnerabilities.

Friday, September 18, 2015

Subtree Sum

Problem

Find subtrees with nodes that add to a given sum

Example Input:

Sum = 5
Tree is:

            1
    /   \
           2     3
         / \   / \
      2  -1 0   8
      /\   /\           /\   /\
   0  3 -5 4     6 -9 -6 1

Output: 

0 3 
null null null null 
--------------------
2 -1 
0 3 -5 4 
null null null null null null null null 
--------------------

Solution

package Tree;

import java.util.ArrayList;

public class SubtreeSum {

	private ArrayList sumPaths;

	private Integer traverse(Tree t, int sum){
		if(t == null) return 0;

		Integer leftSum = traverse(t.left, sum);
		Integer rightSum = traverse(t.right, sum);
//		if(leftSum == null || rightSum == null) return null;
		Integer curSum = leftSum + rightSum + t.val;

//		if(curSum > sum) return null;
		if(curSum == sum) { sumPaths.add(t);}
		return curSum;
	}
	
	public void printSubTreeWithSum(Tree t, int sum){
		sumPaths = new ArrayList();
		traverse(t, sum);
		
		for(int i = 0; i < sumPaths.size(); i++){
			TreeOperations.printTree(sumPaths.get(i));
			System.out.println("--------------------");
		}
	}
	
	public static void main(String[] args) {
		SubtreeSum ob = new SubtreeSum();
		Tree t = TreeTestData.getSampleTree3();
		ob.printSubTreeWithSum(t, 5);
	}
}

Tree - Sum Paths

Problem

Given a binary tree, not necessarily a BST return all paths with sum x:
Example for sum =5 and tree given below:

         1
        /   \
           2     3
         / \          / \
      2  -1      0   8
      /\   /\       /\     /\
   0  3 -5 4   6 -9 -6 1

Output is: [[1,2,2],[2,3],[1,2,2,0],[2,-1,4],[3,8,-6]]

Solution

public class Tree{
	int val;
	Tree left;
	Tree right;
} 

package Tree;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class TreeSumPath {

	Set< ArrayList<Integer> > sumPaths2;
	
	void doTraversal(Tree t, int remain, int oSum, ArrayList temp){
		temp.add(t.val);
		if(remain == 0) sumPaths2.add(temp);
		traverse2(t.left, remain, temp, oSum);
		traverse2(t.right, remain, temp, oSum);
	}
	
	void traverse2(Tree t, int sum, ArrayList curNodes, int oSum){
		if(t==null) return;
		ArrayList temp = new ArrayList(curNodes);
		doTraversal(t, sum - t.val, oSum, temp);
		
		temp = new ArrayList();
		doTraversal(t, oSum-t.val, oSum, temp);
	}

	Set< ArrayList<Integer> > getSumPaths(Tree t, int sum){
		sumPaths2 = new HashSet< ArrayList>();
		traverse2(t, sum, new ArrayList(), sum);
		System.out.println(sumPaths2);
		return sumPaths2;
	}
	
	public static void main(String[] args) {
		Tree t = TreeTestData.getSampleTree3();
		TreeSumPath ob = new TreeSumPath();
		ob.getSumPaths(t, 5);
	}
}

Thursday, September 17, 2015

Gold Bug

Problem

Solve the gold bug story's cipher

Note: This is from Mark Stamp's Information Security: Principles and Practice book, chapter 2. Solution below was submitted as homework for CS265 Cryptography and Information Security class at San Jose State University.

Solution

The cipher is a substitution cipher. Analysis of the frequency counts of letters and words in the English language were used to convert the cipher text to plain text.

The original cipher text is:
53++!305))6*;4826)4+.)4+);806*;48!8`60))85;;]8*;:+*8!83(88)5*!;
46(;88*96*?;8)*+(;485);5*!2:*+(;4956*2(5*-4)8`8*; 4069285);)6
!8)4++;1(+9;48081;8:8+1;48!85;4)485!528806*81(+9;48;(88;4(+?3
 4;48)4+;161;:188;+?;

Since e is the most frequently occurring letter in the English language, and 8 is the most frequently occurring character (34 times) in the above cipher, we make an intelligent guess that ‘e’ is mapped to the letter 8. So we get:
53++!305))6*;4e26)4+.)4+);e06*;4e!e`60))e5;;]e*;:+*e!e3(ee)5*!;
46(;ee*96*?;e)*+(;4e5);5*!2:*+(;4956*2(5*-4)e`e*; 40692e5);)6
!e)4++;1(+9;4e0e1;e:e+1;4e!e5;4)4e5!52ee06*e1(+9;4e;(ee;4(+?3
4;4e)4+;161;:1ee;+?;

‘The’ is the most common 3 word in English with the letter e and correspondingly we find several instances of “;4e” above. So we guess that ; is t, 4 is h. By replacing those we get:
53++!305))6*the26)h+.)h+)te06*the!e`60))e5tt]e*t:+*e!e3(ee)5*!t
h6(tee*96*?te)*+(the5)t5*!2:*+(th956*2(5*-h)e`e*t h0692e5)t)6
!e)h++t1(+9the0e1te:e+1the!e5th)he5!52ee06*e1(+9thet(eeth(+?3
hthe)h+t161t:1eet+?t

We then guess that the below words in the below order:
t(ee – tree
thr+?3h – through
!egree – degree
th6rtee* - thirteen
5nd – and
degree) – degrees
9inutes – minutes
1rom – from
fift: - fifty
0eft – left
de`ils – devils
2y – by
bisho.s – bishops
bran-h - branch
t]enty one – twenty one



5
2
-
!
8
1
3
4
6
0
9
*
+
.
(
)
;
?
`
:
]
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
y
w

Plain text:
a good glass in the bishops hostel in the devils sea twenty one degrees and thirteen minutes north east and by north main branch seventh limb east side shoot from the left eye of the deaths head a beeline from the tree through the shot fifty feet out

This cryptanalytic success leads to a plain text puzzle with no punctuations. As Legrand recognizes the words, he adds spaces. Then he splits the words into groups that make sense, by making use of the fact that people tend overcrowd details together when they try to make a crypt without punctuations, making the 5 groups stand out.

Groups:
A good glass in the bishop's hostel in the devil's --twenty-one degrees and thirteen minutes --northeast and by north --main branch seventh limb east side --shoot from the left eye of the death's-head --a bee-line from the tree through the shot fifty feet out.

As a result of the cryptanalytic success, Ledger figures out the secret location of the pirate’s (Kidd) treasure from the plain text. With the help of a friend and his caretaker, he digs out the treasure from the location.

Reference:

Story - http://poestories.com/read/goldbug

Double Transposition Matrix

Problem

Decrypt the ciphertext
IAUTMOCSMNIMREBOTNELSTRHEREOAEVMWIHTSEEATMAEOHWHSYCEELTTEOHMUOUFEHTRFT
This message was encrypted with a double transposition using a matrix of 7 rows
and 10 columns. Hint: The first word is “there.”

Note: This is from Mark Stamp's Information Security: Principles and Practice book, chapter 2. Solution below was submitted as homework for CS265 Cryptography and Information Security class at San Jose State University.

Solution

Step 1: Spread the ciphertext across a  7x10 matrix

0
1
2
3
4
5
6
7
8
9
0
I
A
U
T
M
O
C
S
M
N
1
I
M
R
E
B
O
T
N
E
L
2
S
T
R
H
E
R
E
O
A
E
3
V
M
W
I
H
T
S
E
E
A
4
T
M
A
E
O
H
W
H
S
Y
5
C
E
E
L
T
T
E
O
H
M
6
U
O
U
F
E
H
T
R
F
T

Step 2: Try to rearrange the columns in at least one row to form the words ‘THERE’. Here we spot ‘HERE’ and see a T in row #2, so we know we can form “THERE” on that row. And we also see that we can form the words “ARE”, “SO” from the remaining letters in that row, so we can form the phrase “THERE ARE SO” in row #2

1
3
4
5
6
8
2
9
0
7
0
A
T
M
O
C
M
U
N
I
S
1
M
E
B
O
T
E
R
L
I
N
2
T
H
E
R
E
A
R
E
S
O
3
M
I
H
T
S
E
W
A
V
E
4
M
E
O
H
W
S
A
Y
T
H
5
E
L
T
T
E
H
E
M
C
O
6
O
F
E
H
T
F
U
T
U
R

Step 3: One of the remaining rows need to have the next word. We can guess the next word to be MANY or “SOME” (taking SO from row #2 and ME from one of the other rows. We can’t form MANY, but can form ME. So we think of the next word and guess it to be WHO. Then we see that we can form ME and WHO on row #4, but need to change the columns, where there were multiple Es  in column 6,4 when we arranged them for row #2. So we get the phrase: THERE ARE SOME WHO SAY TH

1
3
6
5
4
8
2
9
0
7
0
A
T
C
O
M
M
U
N
I
S
1
M
E
T
O
B
E
R
L
I
N
2
T
H
E
R
E
A
R
E
S
O
3
M
I
S
T
H
E
W
A
V
E
4
M
E
W
H
O
S
A
Y
T
H
5
E
L
E
T
T
H
E
M
C
O
6
O
F
T
H
E
F
U
T
U
R

Step 4: The TH at the ending of our phrase can only be THAT. We see that row #1 has AT to complete the word THAT. So we rearrange the rows to form the phrase: THERE ARE SOME WHO SAY THAT COMMUNIS

1
3
6
5
4
8
2
9
0
7
2
T
H
E
R
E
A
R
E
S
O
4
M
E
W
H
O
S
A
Y
T
H
0
A
T
C
O
M
M
U
N
I
S
1
M
E
T
O
B
E
R
L
I
N
3
M
I
S
T
H
E
W
A
V
E
5
E
L
E
T
T
H
E
M
C
O
6
O
F
T
H
E
F
U
T
U
R

Step 5: COMMUNIS can either be COMMUNISM or COMMUNIST. Row #1, 3 help to form COMMUNISM, but row #3 has IS THE WAVE as coherent English phrase. So we pick that as the next row to get: THERE ARE SOME WHO SAY THAT COMMUNISM IS THE WAVE

1
3
6
5
4
8
2
9
0
7
2
T
H
E
R
E
A
R
E
S
O
4
M
E
W
H
O
S
A
Y
T
H
0
A
T
C
O
M
M
U
N
I
S
3
M
I
S
T
H
E
W
A
V
E
1
M
E
T
O
B
E
R
L
I
N
5
E
L
E
T
T
H
E
M
C
O
6
O
F
T
H
E
F
U
T
U
R

Step 6: Next possible word could be OF or TO. We can find OF in row #6, but can’t find TO. So using row #6, we now get: THERE ARE SOME WHO SAY THAT COMMUNISM IS THE WAVE OF THE FUTUR

1
3
6
5
4
8
2
9
0
7
2
T
H
E
R
E
A
R
E
S
O
4
M
E
W
H
O
S
A
Y
T
H
0
A
T
C
O
M
M
U
N
I
S
3
M
I
S
T
H
E
W
A
V
E
6
O
F
T
H
E
F
U
T
U
R
1
M
E
T
O
B
E
R
L
I
N
5
E
L
E
T
T
H
E
M
C
O

Step 7: FUTUR can only be FUTURE and row #5 hence forms the next row and we get back the original matrix with the phrase: THERE ARE SOME WHO SAY THAT COMMUNISM IS THE WAVE OF THE FUTURE LET THEM COME TO BELIN

1
3
6
5
4
8
2
9
0
7
2
T
H
E
R
E
A
R
E
S
O
4
M
E
W
H
O
S
A
Y
T
H
0
A
T
C
O
M
M
U
N
I
S
3
M
I
S
T
H
E
W
A
V
E
6
O
F
T
H
E
F
U
T
U
R
5
E
L
E
T
T
H
E
M
C
O
1
M
E
T
O
B
E
R
L
I
N

Step 8: Add punctuation marks to get lines from John F. Kennedy’s famous speech from 1963.

Plaintext:
THERE ARE SOME WHO SAY THAT COMMUNISM IS THE WAVE OF THE FUTURE. LET THEM COME TO BELIN.