Jump to content

need help with coding


oracle259

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.
Link to comment
https://forums.phpfreaks.com/topic/24861-need-help-with-coding/
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.
Link to comment
https://forums.phpfreaks.com/topic/24861-need-help-with-coding/#findComment-113308
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.
Link to comment
https://forums.phpfreaks.com/topic/24861-need-help-with-coding/#findComment-113339
Share on other sites

Archived

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

×
×
  • Create New...

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.