PureBASIC Challenge #2!

Everything else that doesn't fall into one of the other PB categories.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

PureBASIC Challenge #2!

Post 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 :-)
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post 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
Mat
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

I PMed you how i did it, don't want to spoil it for anyone else :)

Looking forward to #3 :D
Mat
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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 :-)
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

All done. It's not as difficult as it may look so good luck everyone! Bring on #3! :P :D
Mat
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Is this really a Trick and Tips ?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Fred wrote:Is this really a Trick and Tips ?
That's what i said :!:
Shouldn't be in Offtopic or General Discussion :?:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

Few, done! Where is #3? :)
Would be move to places as Psychophanta told.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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 ;)
Post Reply