Announcement

Collapse
No announcement yet.

Split String into Characters

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Split String into Characters

    I am doing this for a http://www.hackthissite.org challenge in which I must get a form coded in Perl to return a non-zero value by inputting an alpha-numeric string that when each character is converted to ASCII values and run through a script operator will match and 'if' statement. Here is the section of the form that checks the input and gives the return value:
    Code:
    sub validkey    //think of it as a function
    {
     if (not($_[0] =~ /[A-Z]|[a-z]|[0-9]/))    //alpha-numeric inputs only
     {
      return 0;
     }
     my @idchars = split(//, $_[0]);     //splits up character from input
     my ($total, $counter, $char) = (0, 0);
     while(defined($idchars[$counter])) //while the counter is not equal to the number of characters in the string
    
     {
      $char = $idchars[$counter]; //get the string value of the current character
      $total += (ascii($char)+($total*$counter)); //straightforward
      $counter++; //next character
     }
    
     if ($total > 925559 && $total < 927901)
     {
    
      return $total;
     }
     else
     {
      return 0;
     }
    }
    In order to do this, you are supposed to write your own program by reverse engineering the form. But since I'm not that good with other languages, I decided to see if this was possible in UnrealScript.

    Edit: See next post.

    #2
    Here's the working code:
    Code:
    exec function int validkey ( string id )
    {
         local int counter;
         local int idchars;
         local int total;
         local string char;
         local string id2;
    
         if ( id != "" )
         {
         idchars = Len(id);
    
         while( counter!=idchars )
         {
              char = id;
              EatStr(id2, char, counter);
              total += (Asc(char)+(total*counter));
              id2 = "";
              counter++;
         }
    
         if (total > 925559 && total < 927901)
         {
              Level.Game.Broadcast(None, string(total)@"Jackpot!");
              return total;
         }
         else
         {
              Level.Game.Broadcast(None, string(total)@"(Should be < 927901 and > 925559)");
              return total;
         }
         } else {
         Level.Game.Broadcast(None, "Use: validkey <string>");
         return 0;
         }
    }

    Comment


      #3
      Edit: Lol I accidentally put Asc(char), when I meant to put Asc(id2). I feel really dumb. Works perfectly btw.

      Comment


        #4
        glad to have been of assistance...

        Comment

        Working...
        X