-1

is there any algo which shuffles characters of a string such that every shuffles return a unique combination, yet can be shuffled back to the original string if we know how many time it was shuffled?

this is what i have so far, yet it s not what i wanted. It can shuffle only (n/2)+1 times after that it comes back to the original string

//scramble data systematicslly
function Scramble($contents)
{
    $fsize=strlen($contents);
    $m=intval($fsize/2);
    $buffer=$contents[$m];
    for($i = 1; $i < $fsize; $i++)
    { 
        if($i%2==0)
        {
            if($m+$i<=$fsize){$buffer.= $contents[$m+$i];}
            if($m-$i>=0){$buffer.= $contents[$m-$i];}
        }else
        {
            if($m+$i<=$fsize){$buffer.= $contents[$m+$i];}
            if($m-$i>=0){$buffer.= $contents[$m-$i];}
        }
    }    
    return $buffer;
}
Nok Imchen
  • 2,802
  • 7
  • 33
  • 59

1 Answers1

-1

Create a function that performs an operation. If you do this you know the process so to find the original string, create another function that takes an integer as a parameter, and do the opposite of your original function n times.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Martin Bean
  • 38,379
  • 25
  • 128
  • 201