构建一个金色的rot13加密器太容易了,因为在ASCII字符空间中字母都是相同的顺序。让我们来试试rot32引擎吧。
您的任务是构建一个函数,该函数以一个Base64字符串作为输入,并返回相同的字符串,但每个字母从其原始字符串中旋转32个符号(本质上,第一个位翻转)。
用于此问题的base64编码字符串是0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/,其填充字符为=。这是为了防止使用或导入内置Base64库的解决方案,其中字符串通常以A而不是0开头。
Example inputs and outputs:
> rot32("THE+QUICK+BROWN+FOX+JUMPS+OVER+THE+LAZY+DOG=")
nb8ukoc6eu5liqhu9irudogjmuip8lunb8uf4tsu7ia=
> rot32("NB8UKOC6EU5LIQHU9IRUDOGJMUIP8LUNB8UF4TSU7IA=")
h5Eoei6C8oBfckboFclo7iadgocjEfoh5Eo9AnmoDc4=
> rot32("Daisy++daisy++give+me+your+answer+true/I+/+m+half+crazy++all+for+the+love+of+you")
7GOY2uuJGOY2uuMO/KuSKu2U+XuGTY0KXuZX+KvcuvuSuNGRLuIXG32uuGRRuLUXuZNKuRU/KuULu2U+在任何语言中这样做的最短程序获胜。
发布于 2014-12-01 04:38:55
q"+"":/{a[A"{,^}/_32m>er在网上试试。
q " Read from STDIN. ";
"+" " Push that string. ";
":/{a[A" " Push that string. ";
{ " For each character in the second string: ";
, " Push the string of all charcters with a lower ASCII code. ";
^ " Take the symmetric difference of the two topmost strings on the stack. ";
}/ " Result: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789'. ";
_32m> " Rotate a copy 32 characters to the right. ";
er " Perform character transliteration. ";发布于 2014-12-01 00:20:24
tr 0-9a-zA-Z+/ w-zA-Z+/0-9a-vSTDIN输入,STDOUT输出。
发布于 2014-11-30 22:56:26
只是一个简单的音译。从STDIN读取,输出到STDOUT:
$_=<>;y#0-9a-zA-Z+/#w-zA-Z+/0-9a-v#;print在这里试试。
https://codegolf.stackexchange.com/questions/42054
复制相似问题