Jump to content


Photo

need help with coding


  • Please log in to reply
6 replies to this topic

#1 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 23 October 2006 - 06:28 PM

Token
da39a3ee5e6b4b0d3255bfef95601890afd80709
Hash
d9e9cc7b89014441757996f67755c7ca1b64e188
Sequence
1211121212

Say that i wanted to combine both token and hash using the above sequence where 1 represents a token character and 2 represents a hash character. eg the sequence would start as follows

dda399ae......


How do i go about accomplishing this.

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 23 October 2006 - 06:39 PM

<?php

$token = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
$hash = "d9e9cc7b89014441757996f67755c7ca1b64e188";
$sequence = "1211121212";

$result = "";

$i = 0;
while ($i <= (strlen($sequence)-1))
{
 if($sequence{$i} == 1) $result .= $token{$i};
 else $result .= $hash{$i};
 
 $i++;
}

echo $result;

?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 23 October 2006 - 07:29 PM

Thanks but it seems like there is a problem the code generated the following sequence d939aceb59 but the sequence im looking for is dda399ae....... also the final output should be around 80 characters how can i modify ur code to accomplish this

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 23 October 2006 - 07:33 PM

My code takes the first letter from token then second from hash, third from token, fourth token... That's how I understood it.
What do you want the code to do?

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 23 October 2006 - 07:49 PM

Oh, I think I know what I mean.

I think this will work.

<?php

$token = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
$hash = "d9e9cc7b89014441757996f67755c7ca1b64e188";
$sequence = "1211121212";

$result = "";

$pos=0;
$num_hash=0;
$num_token=0;
$i=0;
while($i  <  ((strlen($hash)) + (strlen($token)) -1))
{
 if($pos == (strlen($sequence)-1)) $pos=0;
 if($sequence{$pos} == 1) {$result .= $token{$num_token}; $num_token++;}
 if($sequence{$pos} == 2) {$result .= $hash{$num_hash}; $num_hash++;}
 $pos++;
 $i++;
}

echo $result;

?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#6 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 23 October 2006 - 07:54 PM

thanks you nailed it

#7 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 23 October 2006 - 08:07 PM

seems like i spoke too soon. I did a strlen on $results and it came to 76 is there a way to continue the process until it comes back to strlen 80




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users