描述
凯撒移位(Caesar Shift)是一种非常简单的单字母密码,其中每个字母都被替换为字母中的一个字母。例:
Hello world! -> IFMMP XPSME!
(IBSLR, EGUFV!
是实际挑战的输出,这是移动1的示例。)
如您所见,空格和标点符号保持不协调。但是,为防止猜测消息,所有字母均大写。通过将字母向后移,可以解密该消息,很方便,但是真的很容易被不知道该消息含义的其他人解密。
因此,我们将通过使用一种高级形式的密码来帮助Caesar:Self-shifting Caesar Shift!
挑战
您的任务是编写一个程序或函数,给定要加密的字符串,然后输出与输入相对应的加密字符串。先进的Caesar Shift的工作方式如下:
1. Compute letter differences of all adjacent letters:
1.1. Letter difference is computed like this:
Position of 2nd letter in the alphabet
-Position of 1st letter in the alphabet
=======================================
Letter difference
1.2. Example input: Hello
H - e|e - l|l - l|l - o
7 - 5|5 - 12|12 - 12|12 - 15 Letter differences: 3; -7; 0; -3
=3| =-7| =0| =-3
2. Assign the letters continously a letter difference from the list,
starting at the second letter and inverting the differences:
2.1. 2nd letter: first difference, 3rd letter: second difference, etc.
2.2. The first letter is assigned a 1.
2.3. Example input: Hello with differences 3; -7; 0; -3
Letter || Value
=======||======
H || 1
E || -3
L || 7
L || 0
O || 3
3. Shift the letters by the value x they have been assigned:
3.1. In case of a positive x, the letter is shifted x letters to the right.
3.2. In case of a negative x, the letter is shifted |x| letters to the left.
3.3. In case of x = 0, the letter is not shifted.
3.4. If the shift would surpass the limits of the alphabet, it gets wrapped around
Example: Y + Shift of 2 --> A
3.5. Example input: See the table under 2.3.
|| || Shifted
Letter || Value || Letter
=======||=======||=========
H || 1 || I
E || -3 || B Program output:
L || 7 || S IBSLR
L || 0 || L
O || 3 || R
在此过程中,将跳过空格和其他特殊符号(例如标点符号)。确保为您的程序提供仅包含可打印ASCII字符的字符串。函数/程序的输出只能是大写。
这是代码高尔夫球,因此存在标准漏洞,并且可能以字节为单位的最短答案胜出!
ZEN
,例如。Z
移1是... A
?(作为一个侧面说明,05AB1E答案转Z
成A
)
RELIEF
和RELIES
这两个加密器相同的结果SRSFAG
?
E
-3
?