Tuesday, April 29, 2008

Fun with Dictionary attack

As part of fun@work , some puzzles or mind game will be given to the work force or resources as they claim to make them relax and also to make them to think a bit. I never enjoyed those really ,so i neaver participated in any of those games.

Last week we had a game ,we have to make as many as possible 3 or more letter meaningful words using the alphabets in the word given below....

"ULTRAREVOLUTIONARIES"


The letters should not be used more than their occurrence in the word above. This was the condition given,

As usual i neither cared at this one nor minded about it. I found one of my colleague screwing his mind to find the possible words. One more was trying to simulate with a piece of code. Code? Problem solving with Programming? Oh hi I got interested.. on looking the question and mail again i got the clue this is nothing but a Dictionary attack ...

What is Dictionary Attack ?

Wiki says ,
In cryptanalysis and computer security, a dictionary attack is a technique for defeating a cipher or authentication mechanism by trying to determine its decryption key or pass phrase by searching a large number of possibilities.

This is the famous attack for password recovery.Generally, dictionary attacks succeed because many people have a tendency to choose passwords which are short (7 characters or fewer), single words in a dictionary, or are simple variations that are easy to predict, such as appending a single digit to a word.

This is why Password Policy are introduced ,which will ask the user to enter a combination of special characters and alphanumeric characters.

The first password i choosed for my mail when i was doing my goody college days is a 5 letter word.At that time iam ignorant and not any more.. :)

Thats the definition for Dictionary Attack . what this gonna do with puzzle given?

When the every one was solving this one with paper and pen with out knowing this attack , I wrote a piece of java code to perform a dictionary attack for the possible rule
"ULTRAREVOLUTIONARIES" ,

Heres the code ,

package com.ashok.work.fun;

import java.io.BufferedReader;
import java.io.FileReader;

public class WordList {

/**
* @author:ashok
* @date :April 25,2008
*/


public static void main(String[] args)throws Exception {


BufferedReader file=new BufferedReader(new FileReader("c:\\words.txt"));
String word=null;//=file.readLine();
while((word=file.readLine())!=null)
{
if(word.length()>3)
{
if(checkForExpression(word))
{
System.out.println(word);
}
}
}


}
public static boolean checkForExpression(String str)
{
//int noOftimes,temp=0;
int u=0,l=0,t=0,r=0,a=0,e=0,i=0,o=0,s=0,n=0,v=0,def=0;
for(int j=0;j {
char tmpChar=str.charAt(j);

switch (tmpChar)
{
case 'u' :
case 'U':
u++;
break;

case 'l' :
case 'L':
l++;
break;

case 't' :
case 'T':
t++;
break;

case 'r' :
case 'R':
r++;
break;

case 'a':
case 'A':
a++;
break;

case 'e' :
case 'E':
e++;
break;

case 'i' :
case 'I':
i++;
break;

case 'o' :
case 'O':
o++;
break;

case 'S' :
case 's':
s++;
break;

case 'n' :
case 'N':
n++;
break;

case 'v' :
case 'V':
v++;
break;

default :
def++;
}

}
if(def>0)
return false;
if((u>2)||(l>2)||(t>2)||(r>3)||(a>2)||(e>2)||(i>2)||(o>2)||(s>1)||(n>1)||(v>1)){
return false;
}
else
return true;
}

}


This program takes a Dictionary file as an input , and looks for the matching word as per the rule given. Getting a Dictionary file is easy and this program depends on the number of words in the Dictionary file .

Any guess how much i was able to generate ? 100 ? No its almost 2000 with 25k words list and 4000 with almost 55k words list dictionary.. And how much they able to generate any guesses? If i am right not more than 10 :) It shows purely IT is the business differentiator and thats why billions of dollars are spend !

Generated the words since the machine have done its perfect so I submitted the words list , and it was rejected , the reason told was that i have Googled for the answer ! so no prize :)

shit what the heck !

But still Programming is Fun !