Program

ramesh.y

New member
Joined
Jun 12, 2008
Messages
2
Programming Experience
Beginner
Hi,

I am a newbie.....I need code for this program

A number is called 'desirable' if all the digits are strictly ascending
eg: 145 as 1<4<5. You know that other person has a strictly numeric passwordthat is 'desirable'. Your close friend has given you the number of digits (N)in other person's password. WAP that takes in 'N' as input and prints out all possible 'desirable' numbers that can be formed with N digits.

Can anyone help me???
 
It sounds like you're wanting to make a program to brute-force WAP crack, based on number of chars.
 
I think the simplest would be a recursive solution. Something like this :

VB.NET:
Public Function GetPasswords(ByVal CharCount As Integer, ByVal minChar As Char) As List(Of String)
        Dim passwords As New List(Of String)()

        For charIterator As Integer = Asc(minChar) To Asc("9"c)
            Dim incompletePassword As String = Chr(charIterator).ToString()

            If (CharCount > 1) Then
                For Each pass As String In GetPasswords(CharCount - 1, Chr(charIterator + 1))
                    passwords.Add(incompletePassword & pass)
                Next
            Else
                passwords.Add(incompletePassword)
            End If
        Next

        Return passwords
    End Function

You can take the condition (CharCount > 1) outside the loop to make the routine more efficient, but it seemed clearer like this.
 
Back
Top