Showing posts with label assessment test interview questions password hacking software optmized solution. Show all posts
Showing posts with label assessment test interview questions password hacking software optmized solution. Show all posts

Thursday, August 21, 2008

Password Hacking software program. Nothing to do with real hacking though.

//This question was never asked to me in any of my interviews, however, after many of my friends asked me for a solution, I decided to blog it. I haven't seen any solution online but i happened to have solved it.. Complexity wise, this is really optimized as far as the looping count is concerned. However, there are ways to reduce the space complexity.

THis is a C-style C# code written like that so that it is easy for C, C++ and Java coders to understand. However, if any one wants an equivalent code in any of the above languages, please email me at chander.utd@gmail.com

To help me keep up the good work please click here and check out some cool stuff.Click here

using System;
using System.Collections.Generic;
using System.Text;
namespace Chander
{
///
/// This class runs a password hacking software.
/// Only two things are given.
/// Hack the password.
/// Only 2 things you know that password is having N digit & each
/// digit in the password is in increasing order example 1469 or 468. [1 ]
///

class Program
{
static int count = 0;
const int c = 9;
static void Main(string[] args)
{
int[] arr = new int[c];
for (int i = 0; i < maxvalue =" getMaxDecimalValue(arr);" arr1 =" new" temp =" string.Empty;" i =" 0;" arr1 =" getAllBinaryNumbers(i" cnt =" 0;" a =" 0;"> result = new List();
if (cnt > 1)
{
for (int a = 0; a < temp =" temp" temp =" temp" arrresult =" new" mod =" 0;" bin =" c;" mod =" val" val =" val">= 1);
return arrResult;
}
private static int getMaxDecimalValue(int[] a)
{
int[] b;
b = new int[a.Length];
int sum = 0;
int k = 0;
for (int i = a.Length - 1; i >= 0; i--)
{
b[i] = 1;
sum = sum + pow(2, k);
k++;
}
return sum;
}
private static int pow(int p, int k)
{
int power = 1;
if (k == 0)
{
return 1;
}
for (int i = 0; i < power =" power">