在 N & 将两个字符串合并在一起X [英] Merge Two strings Together at N & X
问题描述
我目前混合了 Stringgs 和整数,我试图找出在 N 处将每个字符串的值合并在一起的方法
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:
加密字符串:npQvFBdZQ4jD6bhAgekjPQ==
EncryptedString: npQvFBdZQ4jD6bhAgekjPQ==
IV: Þá]ÕVâ×,娽kÜVü
IV: Þá]ÕVâ×,娽kÜVü
哈希:7
因此,一旦合并,字符串将是:长度为 41 个字符.
So, once merged the string would be: 41 characters in length.
预期结果大致如下:
7nÞpáq]vÕFVBâd×Z,qå4¨j½Dk6ÜbVhüAgekjPQ==
7nÞpáq]vÕFVBâd×Z,qå4¨j½Dk6ÜbVhüAgekjPQ==
所以,Hash 在数组的开头,EncryptedString 的 peices 是每个偶数迭代(2,4,6,8).IV 将出现在每个奇数上(不包括 1 [So, 3,5,7,9]).直到到达 IV 的末尾,因此 EncryptedString 的剩余部分将附加到字符串的末尾.
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
所以,简化:在 N 和 X 处合并字符串.
So, simplified: Merge strings together at N and X.
N 是偶数
X 为奇数(不包括第一个)
X Being odd (excluding the first)
推荐答案
我想出了这个结果.不完全是最优雅的,但它的作用就像一个魅力:
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;
}
这篇关于在 N & 将两个字符串合并在一起X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!