[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Code Breaker

Code Breaker

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by WRTIII   Canada  (76 posts)  [Biography] bio
Date Mon 08 Jul 2002 11:47 AM (UTC)
Message
Alright I've been thinking on this script for quite sometime.. I honestly am at a loss of even where to begin..

I have a safe I wish to crack.. If has 3 Dials Each is a number from 1 - 9

So I need a script that will go from 1 1 1 to 1 1 2 1 1 3 and so on up to 9 9 9 or until the safe opens

The syntax to change each dial is

TURN DIAL # to #

Then I would need to try and OPEN SAFE
It would either Say THE SAFE IS LOCKED or THE SAFE IS NOW OPEN.

Anyhelp in this matter would be appreciated cause I am stumped thanks,

wrtiii
[Go to top] top

Posted by Dubthach   (47 posts)  [Biography] bio
Date Reply #1 on Mon 08 Jul 2002 02:38 PM (UTC)

Amended on Mon 08 Jul 2002 02:46 PM (UTC) by Dubthach

Message
[Ha ha, I just noticed this was in the VBScript forum. You poor lost soul! Guess you'll have to adapt the script more, since it ain't in VB. :P I'm guessing there are while loops in VB, so it probably won't be that bad.

*wanders off to get some Mt. Dew and wake up*]

OK. I didn't have time to really hack this out for you, but this should get you started. Here's a perl script that prints out every combination that your safe could possibly have:


my $min_dial = 1;
my $max_dial = 10;
my $dial_one = $min_dial;
my $dial_two = $min_dial;
my $dial_three = $min_dial;

#change all prints to mushclient $world -> send commands (take off \n)

while ($dial_one <= $max_dial)
{
	print "TURN DIAL 1 TO $dial_one\n";

	while ($dial_two <= $max_dial)
	{
		print "TURN DIAL 2 to $dial_two\n";

		while ($dial_three <= $max_dial)
		{
			print "TURN DIAL 3 TO $dial_three\n";

			$dial_three++;
		}

		$dial_two++;
		$dial_three = $min_dial;
	}

	$dial_one++;
	$dial_two = $min_dial;
}


Now, you'll have to adapt this to mushclient. The prints have to be changed to use the mushclient method that sends tax to your mud. And, you're probably going to want to stop your crack after you find the correct combination. So, you should add a simple trigger that just sets a variable to true or false, and check that value after every print. Send a return if the variable indicates the safe has cracked.

HTH,
Dubthach
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #2 on Mon 08 Jul 2002 06:47 PM (UTC)
Message
OK. Lets try this, which will be mostly like what Dubthach suggested, but this one should work. ;)

Alias: SCrack
Script: Crackit
Label: CrackStart

Trigger: THE SAFE IS LOCKED
Script: Crackit
Label: Cracktrig
Sub Crackit (Name, Output, Wildcards)
  int diala
  int dialb
  int dialc
  if Name = "CrackStart" then
    world.enabletrigger "Cracktrig", True
    diala = 1
    dialb = 1
    dialc = 1
    world.send "turn dial 1 to " & diala
    world.send "turn dial 2 to " & dialb
    world.send "turn dial 3 to " & dialc
    world.send "open safe"
  else
    diala = Cint(world.getvariable ("diala"))
    dialb = Cint(world.getvariable ("dialb"))
    dialc = Cint(world.getvariable ("dialc"))
    dialc = dialc + 1
    if dialc > 9 then
      dialc = 1
      dialb = dialb + 1
      if dialb > 9 then
        dialb = 1
        diala = diala + 1
        world.send "turn dial 1 to " & diala
        world.send "turn dial 2 to " & dialb
        world.send "turn dial 3 to " & dialc
        world.send "open safe"
      else
        world.send "turn dial 2 to " & dialb
        world.send "turn dial 3 to " & dialc
        world.send "open safe"
      end if
    else
      world.send "turn dial 3 to " & dialc
      world.send "open safe"
    end if
  end if
  world.setvariable "diala",diala
  world.setvariable "diala",dialb
  world.setvariable "diala",dialc
end sub

Yours won't work Dubthach because even if you used perlscript in the client the script doesn't execute in its own thread, instead it would continue to loop through every single combo until it exited, because new information from the mud is never recieved until 'after' a script routine exits. This is also why you have to use global variables or mushclient variables to store values you want to keep.
[Go to top] top

Posted by Dubthach   (47 posts)  [Biography] bio
Date Reply #3 on Mon 08 Jul 2002 08:27 PM (UTC)
Message
It's interesting that you say my code "won't work". Actually, it does exactly what I advertized it as doing. Yes, its incomplete...and yes, you found one way around the problem of how to implement the trigger. However, I'm not in the habit of giving out completed scripts to people...doing their homework as it were. My intention was to show how the algorithm for checking all combinations could be implemented.

IMHO, it would be silly to run this script as it is written above. Most likely the player would get booted from the mud for sending ridiculous spam. The player should take the simple algorithm suggested and write several routines to do the job in a more controlled way.

HAND.

Dub.
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #4 on Mon 08 Jul 2002 11:16 PM (UTC)
Message
>Actually, it does exactly what I advertized it as doing.

Yes technically it does.

>IMHO, it would be silly to run this script as it is written above.

Yes very. I was mearly stating the obvious. That as is the code 'would' not work the way 'he' needed it to. In fact since you can't use loops of this sort in a script and get the expected result it only helps to confuse things to show one that assumes that it does work imho. i.e. You can't functionally use while loops, so suggesting them is inappropriate, much as suggesting recursion would be if coding in a language that doesn't allow it. I didn't mean any sort of insult by it, I was just stating a fact. Though I admit I did perhaps presume about your own understanding of how it needed to work based on your example. I am sorry.
[Go to top] top

Posted by WRTIII   Canada  (76 posts)  [Biography] bio
Date Reply #5 on Wed 10 Jul 2002 10:01 PM (UTC)
Message
Ok Having troubles with what I got so far... but it gave me ideas...

How Can I take the number 999 and assign the first digit to A the second to B and the Third to C That way..
I can just do
Do
Code=111
A=First Digit
B=2nd
C=3rd
turn 1 to a
turn 2 to b
turn 3 to c
Code =Code + 1
Loop

If I recall VB Right it was something like Lint(#,#,varbiel) or something It's been so long....

It would be nice to be able to control it somehow.. Maybe even if I could remove the do loop assign them to permanet varibles and have a alias to start a timer that will run it each time set for 10 second intervals... That way All I need to do is have a alias to start timer and 1 to stop I sit there when it gets crack I stop timer Next time I want to do it it will pick up from there... So then I would need to make a If code=999 then code=111... in there..
[Go to top] top

Posted by Nick Gammon   Australia  (22,981 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Wed 10 Jul 2002 11:34 PM (UTC)
Message
Do this:

a = mid (variable, 1, 1)
b = mid (variable, 2, 1)
c = mid (variable, 3, 1)

Or maybe, it starts at zero, I'm not at my computer right now. (ie. 0, 1, 2, not 1, 2, 3)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WRTIII   Canada  (76 posts)  [Biography] bio
Date Reply #7 on Thu 11 Jul 2002 12:40 AM (UTC)
Message
MID !! ya that's it :)

I wish I had my old VB Class notes hehe :)
Thanks Nick
[Go to top] top

Posted by WRTIII   Canada  (76 posts)  [Biography] bio
Date Reply #8 on Thu 11 Jul 2002 01:03 AM (UTC)
Message
Sub Crackit (Thename, theoutput, thewildcards)

Dim CODE
Dim A
Dim B
Dim C

CODE=world.getvariable ("CODE")

A = mid (CODE, 1, 1)
B = mid (CODE, 2, 1)
C = mid (CODE, 3, 1)
world.send "TURN 1 TO " & A
world.send "TURN 2 TO " & B
world.send "TURN 3 TO " & C
world.send "open safe"
CODE=CODE + 1
world.setvariable Code, Code

End Sub

That's what I got so far... The problem I am having is the CODE=CODE + 1... That is not working as I thought it would... I plan to though in an enabletimer... and then have a trigger to react on the safe opening to disable the timer... that way I can control it also an alias to shutdown the timer so I can do it manualy per say if I so wish.. Anyways Adding 1 is the biggest problem right now I guess Please help Thanks

wrtiii
[Go to top] top

Posted by Vaejor   (120 posts)  [Biography] bio
Date Reply #9 on Thu 11 Jul 2002 02:12 AM (UTC)

Amended on Thu 11 Jul 2002 02:20 AM (UTC) by Vaejor

Message
Try this(currently untested)

Alias: SCrack
Script: Crackit
Label: CrackStart

Trigger: THE SAFE IS LOCKED
Script: Crackit
Label: Cracktrig

Dim dial

Sub CrackIt(ByVal strName, ByVal strLine, ByVal astrParam())
  Dim olda, oldb
  Dim newa, newb, newc
  
  olda = Mid(dial, 1, 1)
  oldb = Mid(dial, 2, 1)

  If (strName = "CrackStart") Then dial = 110

  Do
    dial = dial + 1
  Loop While (dial > 100 And dial < 1000 And InStr(1, dial, "0", vbTextCompare) <> 0)

  If (dial >= 1000) Then
    world.Note "All dial turns tried"
    Exit Sub
  End If

  newa = Mid(dial, 1, 1)
  newb = Mid(dial, 2, 1)
  newc = Mid(dial, 3, 1)
  
  If (olda <> newa) Then world.Send "turn dial 1 to " & newa
  If (oldb <> newb) Then world.Send "turn dial 2 to " & newb
  world.Send "turn dial 3 to " & newc
  world.Send "open safe"
  
End Sub
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #10 on Thu 11 Jul 2002 06:55 AM (UTC)

Amended on Thu 11 Jul 2002 07:18 AM (UTC) by Magnum

Message
Do...While loops are usually a no-no in MUSHclient scripts. They stall the client until the loop is complete. (Nothing else is processed). You must use triggers to repeat actions.

Alias: ^autocrack[ ]?(.*)$
Regular Expression: Checked
Label: Autocrack
Script: Autocrack

Sub Autocrack (AliasName, AliasLine, arrWildcards)
	If IsNumeric(Trim(arrWildcards(1))) Then
		World.AddTimer "CrackItTimer", 0, CInt(Trim(arrWildcards(1))), 0, "", 5, ""
		Call AttemptCrack "AutoCrack", Empty, Empty
	Else
		World.DeleteTimer "CrackItTimer"
		World.Note "Crack Timer Deleted."
	End If
End Sub

Alias: ^crackit[ ]?(.*)$
Regular Expression: Checked
Label: crackit
Script: CrackIt

Sub CrackIt (AliasName, AliasLine, arrWildcards)
	Dim Code
	Code = Trim(ArrWildcards(1))
	If (NOT IsNumeric(Code)) OR (Len(Code)) <> 3 Then
		Code = World.GetVariable("CrackItCode")
		If Code = Empty Then Code = "111"
	End If
	World.SetVariable "CrackItCode", Code
	Call AttemptCrack "CrackIt", Empty, Empty
End Sub

Sub Attempt_Crack (Triggername, TriggerLine, ArrWildcards)
	Dim A,B,C
	Dim Code
	Code = World.GetVariable("CrackItCode")
	If Code = Empty Then Code = "111"
	If (Triggername = "CrackIt") OR (World.IsTimer("CrackItTimer") Then
		A = Mid(Code, 1, 1)
		B = Mid(Code, 2, 1)
		C = Mid(Code, 3, 1)
		World.Note "Trying: " & A & B & C
		World.Send "TURN 1 TO " & A
		World.Send "TURN 2 TO " & B
		World.Send "TURN 3 TO " & C
		World.Send "open safe"
		C = CInt(C) + 1
		If C > 9 Then
			C = 1
			B = CInt(B) + 1
		End If
		If B > 9 Then
			B = 1
			A = CInt(A) + 1
		End If
		If A > 9 Then
			A = 1
			B = 1
			C = 1
		End If
		World.SetVariable "CrackItCode", CStr(A) & CStr(B) & CStr(C)
	End If
End Sub

Trigger: THE SAFE IS LOCKED
Label: CrackFail
Script: Attempt_Crack

Whew, all of that written here from scratch, with no easy means of testing it.

Use "autocrack" alias to set the timer, OR to turn it off. If you supply a number, the timer will be on for that many minutes. (Change the addtimer line if you want to make it seconds instead). If you don't supply an argument, or if it's an illegal argument, the timer will be deleted. The alias will also start the cycle by making an attempt.

Use "crackit" alias to make a single attempt. With no argument (or illegal argument), it will try and continue from where it left off. (If it can't, it will reset to "111"). OR, if you choose, supply a three digit number to reset the cracking to that number. For example "crackit 111" will start from the beginning.

Build a trigger to fire on the failure message. This will call the "Attempt_Crack" routine, which checks to see if the timer is active. if so, it tries again, if not, it does nothing.

As I said, I haven't tested this. I think it's impossible to write script in one go without bugs, so let me know what problems you have, and I will try to advise fixes.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Nick Gammon   Australia  (22,981 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Thu 11 Jul 2002 07:18 AM (UTC)
Message
Quote:

The problem I am having is the CODE=CODE + 1... That is not working as I thought it would.


Try: code = cint (code) + 1

That will convert the code to an integer, otherwise you are likely to get 111, 1111, 11111 and so on.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #12 on Thu 11 Jul 2002 07:27 AM (UTC)
Message
Quote:

Try: code = cint (code) + 1

He says in the first message that the safe does not use 0's, so a line like that one will not work. Instead, must do what I show in my script above.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by WRTIII   Canada  (76 posts)  [Biography] bio
Date Reply #13 on Fri 12 Jul 2002 08:03 AM (UTC)
Message
Sub Crackit (Thename, theoutput, thewildcards)
Int CODE
Int A
Int B
Int C
CODE=world.getvariable ("CODE")
A = mid (CODE, 1, 1)
B = mid (CODE, 2, 1)
C = mid (CODE, 3, 1)
world.send "TURN 1 TO " & A
world.send "TURN 2 TO " & B
world.send "TURN 3 TO " & C
world.send "open safe"
CODE = CODE + 1
If CODE = 1000 Then
CODE = 111
world.setvariable "Code", Code
Else
world.setvariable "Code", Code
End If
End Sub


Ok That is the Code I am using right now which is a manualy code and works Awsome From 111 to 999 over and over..
Problem is that I realized the Safe does use zeros.. Well It's no problem for anything 100 and above but I need a way to show 99 and below as 001 010 099 etc. I thought of con... Hmm ..
Hmm Dim AlphaCode
AlphaCode=Code
Do the mid and all on AlphaCode... But do the rest to Code still...
that might work...
[Go to top] top

Posted by WRTIII   Canada  (76 posts)  [Biography] bio
Date Reply #14 on Fri 12 Jul 2002 08:07 AM (UTC)
Message
Hmm Duh No That don't work Cause It takes Code as a number still... Hmmm
I just need to adjust it from 111-999
to
000-999

tahnks
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


61,217 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]