Jump to content

Archived

This topic is now archived and is closed to further replies.

oracle259

need help with coding

Recommended Posts

[b]Token[/b]
da39a3ee5e6b4b0d3255bfef95601890afd80709
[b]Hash[/b]
d9e9cc7b89014441757996f67755c7ca1b64e188
[b]Sequence[/b]
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.

Share this post


Link to post
Share on other sites
[code]<?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;

?>[/code]

Orio.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Oh, I think I know what I mean.

I [i]think[/i] this will work.

[code]<?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;

?>[/code]

Orio.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.