0

I've currently got a mixture of Stringgs and integers which i am trying to figure out the method to merge the values of each string together at N

Here is the three strings/intergers i've got:

EncryptedString: npQvFBdZQ4jD6bhAgekjPQ==

IV: Þá]ÕVâ×,娽kÜVü

Hash: 7

So, once merged the string would be: 41 characters in length.

Expected results would be something along the lines of:

7nÞpáq]vÕFVBâd×Z,qå4¨j½Dk6ÜbVhüAgekjPQ==

So, Hash is at the beginning of the array, peices of EncryptedString is every even iteration (2,4,6,8).. IV would be on every odd occourance (excluding 1 [So, 3,5,7,9]). Until the end of IV has been reached, so then the remainding of EncryptedString would be appended to the end of the string.

this is a logical mind screw and i'm stumped on the iterations on how to perform such a thing

So, simplified: Merge strings together at N and X.

N being even

X Being odd (excluding the first)

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69

1 Answers1

0

I have come up with this result. Not exactly the most elegant, but it works like a charm:

function String_Merge($Array){

    $Encrypted_String = $Array['EncryptedString'];
    $IV = $Array['IV'];
    $Hash = $Array['Hash'];
    $EncStr_Arr = str_split($Encrypted_String);

    $Count = strlen($IV);
    $Increment = 0;
    $String = "";
    $String .= $Hash;
    While ($Increment < $Count){
        $String .= $IV[$Increment];
        $String .= $Encrypted_String[$Increment];
        unset($EncStr_Arr[$Increment]);
        $Increment++;
    }
    $Encrypted_String = implode("",$EncStr_Arr);
    return $String.$Encrypted_String;

}
Daryl Gill
  • 5,464
  • 9
  • 36
  • 69