盒子
盒子
文章目录
  1. 编程?游戏?
  2. 代码实现
  3. 结果

今天玩了一款让我写代码的游戏

编程?游戏?

今天看到一个有趣的网站,这是个通过游戏的形式学习python的网站,玩到了第二关pythonchallenge,很有意思,虽然作者的本意是让玩家学习python,但是我决定用PHP…

游戏中给出了一张图,图里面是这样的提示:

1
2
3
E -> G
K -> M
O -> Q

然后给出了一段”乱码”:

1
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.

显然,只要把“乱码”中每个字母往后移动两位即可…

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.";
$arr = str_split($str);
$res = [];
$filter = [' ','.','\'','(',')'];
foreach ($arr as $item){
if(in_array($item,$filter)) {
$res[] = $item;
continue;
}
$tmp = ord($item);
$res[] = $item == 'z' ? 'b' : ($item == 'y' ? 'a' : chr($tmp + 2));
}
$str = implode($res,'');
echo $str;

结果

i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that’s why this text is so long. using string.maketrans() is recommended. now apply on the url.

请我喝一杯咖啡
扫一扫,支持funsoul
  • 微信扫一扫