PHP动态创建字母 [英] PHP dynamic creation of alphabet
问题描述
我想造成一些麻烦.首先,我想告诉您这是什么意思,以便您了解我这样做的原因:
I would like to create some arrys. First of all I would like to tell you what it is about so that you understand why I am doing this:
密码学.
我想用字母创建一个数组.
I want create an array with the alphabet.
例如
$a1 = array("a"=>"b", "b"=>"c",....,"z"=>a");
好吧,这只是键入的一部分,所以现在我想多做一点.在这种情况下,它是x + 1 = y或换句话说,是用于解码x = y-1
Alright, that is just a bit of typing so now I want to do it a bit more often. In this case it is x+1=y or in other words for the decoding x=y-1
所以可以说,我希望将位置从1更改为26来实现-我将拥有26个数组.
So lets say I would like to do that with a position change from 1 to 26 - I would have 26 arrays than.
在php中,加密和解密本身不是问题,不是我要的,因为它是简单的字符串替换.但是我想知道是否有这样的事情可以通过告诉以下动态方式来创建:
The encryption and decryption itself is not that problem in php and not what I am asking for as it is simple string replacement. But I was wondering if there is anything like this possible to create in an dynamic way by telling:
createAlphabets(1,12)
createAlphabets(1,12)
它创建了一个包含12个字母键的多维数组?
and it creates me a multidimensional array with 12 alphabet keys?
这是我问题的第二部分:
This is the second part of my question:
在数学上是否存在通过计算交换字符的更多可能性?
is there mathematically figure of more possibilities to swap characters by calculation?
我的意思是,x + 5-3 = y与x + 2 = y相同,所以我计算出它被26个数组覆盖了吗?所以即使我说:x-5 + 3 = y =? x-2 = y就像x + 24 = y一样吗?是不是请不要费心告诉我它可能是+25或+23,并且我将不会有24个阵列-上午8点,我没有睡觉-我只是在询问原理-我不想让你做我的工作-我是只是寻找一些确认和想法.
I mean, x+5-3=y is the same like x+2=y so however I calculate it is covered by my 26 arrays? so even if I say: x-5+3=y =? x-2=y it is the same like x+24=y ? isnt it? Please dont bother telling me it might be +25 or +23 and that I am not going to have 24 arrays - its 8am and I didnt sleep - I am just asking about the principle - I dont want you to do my work - I am just looking for some comfirmation and an idea.
推荐答案
$chars = range('a', 'z');
$shift = 5;
$shifted = array_merge(array_slice($chars, $shift), array_slice($chars, 0, $shift));
$alphabet = array_combine($chars, $shifted);
由于字母中有26个字符,因此您只能将它们移动26个字符,这意味着有26种可能的组合.
Since there are 26 characters in your alphabet you can only shift them by 26 characters, meaning there are 26 possible combinations.
这篇关于PHP动态创建字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!