Descrizione
A Caesar Shift è una cifra monoalfabetica molto semplice in cui ogni lettera viene sostituita da una dopo l'alfabeto. Esempio:
Hello world! -> IFMMP XPSME!
( IBSLR, EGUFV!
è l'output per la vera sfida, questo è stato un esempio di spostamento di 1.)
Come puoi vedere, la spaziatura e la punteggiatura rimangono intatte. Tuttavia, per evitare di indovinare il messaggio, tutte le lettere sono in maiuscolo. Spostando indietro le lettere, il messaggio è stato decifrato, conveniente, ma anche molto facile da decifrare da altre persone che dovrebbero non sapere cosa significhi il messaggio.
Quindi, aiuteremo Cesare un po 'usando una forma avanzata del suo codice: il Caesar Shift a spostamento automatico !
Sfida
Il tuo compito è scrivere un programma o una funzione che, data una stringa da codificare, emetta la stringa crittografata corrispondente all'input. L'avanzato Caesar Shift funziona così:
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
Gli spazi e altri simboli speciali, come la punteggiatura, vengono saltati in questo processo. È garantito che al programma verrà assegnata una stringa contenente solo caratteri ASCII stampabili. L'output della tua funzione / programma deve essere solo in maiuscolo.
Questo è code-golf , quindi si applicano scappatoie standard e può vincere la risposta più breve in byte!
ZEN
esempio. Z
spostato di 1 è ... A
? (come nota a margine, la risposta 05AB1E si trasforma Z
in A
)
RELIEF
e RELIES
cifrare entrambe allo stesso risultato SRSFAG
?
E
-3
?