A little Brute Force engine for B+

Miscellaneous Forums/Blitz Showcase/A little Brute Force engine for B+

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's BlitzMAX version of the engine. Much faster and supports longer candidates and stuff:

29 different symbols and 6 lettered candidate takes longer than an hour :(

Example output:
Starting candidates with 1 letters and 29 possibilities...
Ended with 0 seconds (1.#INF0000/s)
Starting candidates with 2 letters and 841 possibilities...
Ended with 0 seconds (841000.000/s)
Starting candidates with 3 letters and 24389 possibilities...
Ended with 0 seconds (393370.969/s)
Starting candidates with 4 letters and 707281 possibilities...
Ended with 3 seconds (180936.563/s)
Starting candidates with 5 letters and 20511149 possibilities...
Ended with 141 seconds (144744.391/s)
Starting candidates with 6 letters and 594823321 possibilities...
FOUND! -> andres


Example:
SuperStrict

Global result:String = "andres"

For Local l:Int = 1 To 10
	Local brute:TBrute = StartBruteforce(l, "abcdefghijklmnopqrstuvwõäöüxy")
	Local total:Long = BruteforceTotal(brute)

	Print "Starting candidates with " + l + " letters and " + total + " possibilities..."
	Local tim:Long = MilliSecs()
	For Local i:Int = 1 To total
		BruteforceNext(brute)
		Local value:String = BruteforceCurrentValue(brute)
		If value = result Then
			Print "FOUND! -> " + value
			End
		EndIf
	Next
	EndBruteforce(brute)
	Print "Ended with " + Int(Float (MilliSecs() - tim) / 1000) + " seconds (" + (total / (Float (MilliSecs() - tim) / 1000)) + "/s)"
Next


Engine:
Type TBrute
	Field length:Long
	Field index:Long
	Field symbols:TBank
End Type

Function StartBruteforce:TBrute(length:Int, symbols:String)
	Local brute:TBrute = New TBrute
		brute.length = length
		brute.index = 0
		brute.symbols = CreateBank(Len(symbols))
		
	For Local i:Int = 1 To Len(symbols)
		PokeByte(brute.symbols, i - 1, Asc(Mid$(symbols, i, 1)))
	Next
	
	Return brute
End Function

Function BruteforceNext:Long(brute:TBrute)
	brute.index :+ 1
	Return brute.index
End Function

Function BruteforceCurrentIndex:Long(brute:TBrute)
	Return brute.index
End Function

Function BruteforceCurrentValue:String(brute:TBrute)
	Local result:String = ""
	Local letters:Long = BankSize(brute.symbols)
	
	For Local i:Int = brute.length To 1 Step -1
		result :+ Chr(PeekByte(brute.symbols, Floor((brute.index - 1) / letters^(i - 1)) Mod letters))
	Next
	
	Return result
End Function

Function BruteforceTotal:Long(brute:TBrute)
	Return BankSize(brute.symbols)^brute.length
End Function

Function EndBruteforce:Int(brute:TBrute)
	brute = Null
	Return True
End Function