Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 阵列偏移加密_Php_Arrays_Offset - Fatal编程技术网

Php 阵列偏移加密

Php 阵列偏移加密,php,arrays,offset,Php,Arrays,Offset,现在我正在开发一个加密应用程序,我对这个有一个问题 $stralphabet=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); 正如你所看到的,上面的字符串是一个字母表字符串。我做的是凯撒移位加密,算法很简单 计算字符串的数量,然后根据位置替换每个字母,例如: string is "AB" after encryption

现在我正在开发一个加密应用程序,我对这个有一个问题

$stralphabet=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
正如你所看到的,上面的字符串是一个字母表字符串。我做的是凯撒移位加密,算法很简单

计算字符串的数量,然后根据位置替换每个字母,例如:

string is "AB" after encryption it would be "CD"
问题是如果我有字符串YZ“它会给我一个错误

Notice: Undefined offset: 26 in C:\xampp\htdocs\cryptographer\encrypt.php on line 19

Notice: Undefined offset: 27 in C:\xampp\htdocs\cryptographer\encrypt.php on line 19

你能帮我解决这个问题吗?

你的数组有26个字母,索引范围从0到25,因此你的循环结束条件有问题。

你显然是在访问
$stralphabel
而没有检查边大小写(即
$stralp[$i+1]
)。您应该添加一些检查或使用
运算符,而不仅仅是:

$stralp[$i+1]
你会的

$stralp[($i+1) % XXX]
其中,
XXX
stralp
数组中的条目数


PS:这甚至不接近加密。

我的问题是数组是否在偏移量上?如何将值返回到0或a?