Page 1 of 1

PureBASIC Challenge #2!

Posted: Sun May 15, 2005 12:49 pm
by Tommeh
Ok, i've finished the second PureBASIC challenge... this one is HARD

To give you all a little head start, the word is randomly chosen from the server, then it is encrypted with a random alphanumeric string a-z A-Z 0-9

Both the encrypted word and the random alphanumeric string is given to you (the client) and its then down to you to reverse the encryption to try and get the origional word, send it to the server and recive the secret password :-)

The encryption is not one way, it can be reversed but it requires a lot of logic, in the following source code for the client you are given the encryption routine in plain PureBASIC, so you should be able to work it out :-)

P.S. The routine is the CheckKeyword() :)

Remember, the word is encrypted using the alphanumeric string which is randomized just for you everytime you connect, you can only have 4 or 5 trys (i can't remember :s!) before you must disconnect and reconnect which will give you a new encrypted word and alphanumeric string (I told you brute forcing will be out of the question)

Well good luck, and here is the source code!

Code: Select all

Global alphanum$

#Server = "athecks.com"
#Port = 12000


Procedure.s CheckKeyword(keyword$)
For t = 1 To Len(keyword$)
  If Asc(Mid(keyword$, t, 1)) > ASCLN And FindString(alphanum$, Mid(keyword$, t, 1), 0) > 0
    Output$ + Bin(Asc(Mid(keyword$, t, 1))+Asc(Mid(keyword$, t-3, 1)))+"1"
    ASCLN = Asc(Mid(alphanum$, t, 1))
  Else
    Output$ + "0"+Bin(Asc(Mid(keyword$, t, 1))+Asc(Mid(keyword$, t-3, 1)))
    ASCLN = 0
  EndIf
Next t
ProcedureReturn Output$
EndProcedure

If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", 0)
  End
EndIf

OpenConsole()
ConsoleTitle("PureBASIC #2 Challenge")
PrintN("Connecting to server...")

ConnID = OpenNetworkConnection(#Server, #Port)

If ConnID
  PrintN("Connected to server!")
  PrintN("Awaiting Alpha & Word keys")
  
  Repeat
  If NetworkClientEvent(ConnID) = 2
    RData$ = Space(500)
    ReceiveNetworkData(ConnID, @RData$, 500)
    
    If StringField(RData$, 1, " ") = "[#01]"
      alphanum$ = StringField(StringField(RData$, 2, " "), 1, ":")
      keyword$ = StringField(StringField(RData$, 2, " "), 2, ":")
      Debug alphanum$
      Debug keyword$
      PrintN("Recived keys")
      PrintN("Alphakey: "+alphanum$)
      PrintN("Keyword: "+keyword$)
      PrintN("")
      PrintN("Please enter the decoded word:")
      password$ = Input()
      PrintN("")
      SendNetworkString(ConnID, password$)
    EndIf
    
    If StringField(RData$, 1, " ") = "[#03]"
      PrintN("Recived password correct signal from server")
      PrintN("From server: "+Right(RData$, Len(RData$)-6))
    EndIf
    
    If StringField(RData$, 1, " ") = "[#04]"
      PrintN(Right(RData$, Len(RData$)-6))
      PrintN("Please enter the decoded word:")
      password$ = Input()
      PrintN("")
      SendNetworkString(ConnID, password$)
    EndIf
    
    If StringField(RData$, 1, " ") = "[#08]"
      PrintN("")
      PrintN(Right(RData$, Len(RData$)-6))
    EndIf
    
  EndIf
  Delay(10)
ForEver
  
Else
  PrintN("Connection refused, please contact Tommeh")
EndIf

Good luck! I think there should be some kind of prize for the first person to PM me the secret from the server, i will think of something :-)

Posted: Sun May 15, 2005 2:46 pm
by MrMat
Sent but i think you're using this slightly simpler code:

Code: Select all

Procedure.s CheckKeyword(keyword$)
For t = 1 To Len(keyword$)
  If Asc(Mid(keyword$, t, 1)) > ASCLN And FindString(alphanum$, Mid(keyword$, t, 1), 0) > 0
    Output$ + Bin(Asc(Mid(keyword$, t, 1)))+"1"
    ASCLN = Asc(Mid(alphanum$, t, 1))
  Else
    Output$ + "0"+Bin(Asc(Mid(keyword$, t, 1)))
    ASCLN = 0
  EndIf
Next t
ProcedureReturn Output$
EndProcedure

Posted: Sun May 15, 2005 2:48 pm
by Tommeh
Very well done MrMat, well your the first one to crack it, was it really pretty easy? :o

I'm gonna have to work really hard on #3, :) you just wait, lmao

Posted: Sun May 15, 2005 2:49 pm
by MrMat
I PMed you how i did it, don't want to spoil it for anyone else :)

Looking forward to #3 :D

Posted: Sun May 15, 2005 2:56 pm
by Tommeh
Lol! Very correct MrMat, i messed up on the server end which made it easier i guess...

Well i've fixed the server end to do it right so it should now give the correct result!

Ok, try and get another of the random words MrMat :-)

Please note: Nothing has/needs to be changed on the code above, thats all the same :-)

Posted: Sun May 15, 2005 3:25 pm
by MrMat
All done. It's not as difficult as it may look so good luck everyone! Bring on #3! :P :D

Posted: Sun May 15, 2005 6:11 pm
by Fred
Is this really a Trick and Tips ?

Posted: Sun May 15, 2005 6:17 pm
by Psychophanta
Fred wrote:Is this really a Trick and Tips ?
That's what i said :!:
Shouldn't be in Offtopic or General Discussion :?:

Posted: Mon May 16, 2005 5:03 am
by sec
Few, done! Where is #3? :)
Would be move to places as Psychophanta told.

Posted: Mon May 16, 2005 8:11 am
by Tommeh
Ok next time i'll post in General discussion, its not really off topic because its still PureBASIC no? :)

MrMat
El_Choni
Sec


Have completed it now :)

#3 is comming soon ;)