oracle259 Posted October 23, 2006 Share Posted October 23, 2006 [b]Token[/b]da39a3ee5e6b4b0d3255bfef95601890afd80709[b]Hash[/b]d9e9cc7b89014441757996f67755c7ca1b64e188[b]Sequence[/b]1211121212Say 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 followsdda399ae......How do i go about accomplishing this. Link to comment https://forums.phpfreaks.com/topic/24861-need-help-with-coding/ Share on other sites More sharing options...
Orio Posted October 23, 2006 Share Posted October 23, 2006 [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 More sharing options...
oracle259 Posted October 23, 2006 Author Share Posted October 23, 2006 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 Link to comment https://forums.phpfreaks.com/topic/24861-need-help-with-coding/#findComment-113327 Share on other sites More sharing options...
Orio Posted October 23, 2006 Share Posted October 23, 2006 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. Link to comment https://forums.phpfreaks.com/topic/24861-need-help-with-coding/#findComment-113332 Share on other sites More sharing options...
Orio Posted October 23, 2006 Share Posted October 23, 2006 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 More sharing options...
oracle259 Posted October 23, 2006 Author Share Posted October 23, 2006 thanks you nailed it Link to comment https://forums.phpfreaks.com/topic/24861-need-help-with-coding/#findComment-113341 Share on other sites More sharing options...
oracle259 Posted October 23, 2006 Author Share Posted October 23, 2006 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 Link to comment https://forums.phpfreaks.com/topic/24861-need-help-with-coding/#findComment-113345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.