Encode with ROT13.5
Given a string, convert all of its letters using ROT13, and all of its digits using ROT5. This is sometimes referred to as ROT13.5.
Input
- A sequence of printable ASCII characters (character codes 32 to 126 inclusive)
- This may be a string or any data structure of characters
Output
- A sequence of characters
- This may be a string or any ordered data structure of characters. It does not need to match the input format (provided it is consistent between inputs)
- For example, you may take input as an array of characters, and output as a string, provided this format does not change for different inputs
- Each character in the output will be determined by the character in the corresponding position in the input, as follows:
- A lower case letter will be replaced with the lower case letter 13 character codes after it, wrapping back to 'a' if 'z' is exceeded
- An upper case letter will be replaced with the upper case letter 13 character codes after it, wrapping back to 'A' if 'Z' is exceeded
- A numeric digit will be replaced with the numeric digit 5 character codes after it, wrapping back to '0' if '9' is exceeded
- Any other character will remain unchanged
Conversion table
Here is the output character for every valid input character, in the format input : output
(the first character is a space, which remains unchanged):
:
! : !
" : "
# : #
$ : $
% : %
& : &
' : '
( : (
) : )
* : *
+ : +
, : ,
- : -
. : .
/ : /
0 : 5
1 : 6
2 : 7
3 : 8
4 : 9
5 : 0
6 : 1
7 : 2
8 : 3
9 : 4
: : :
; : ;
< : <
= : =
> : >
? : ?
@ : @
A : N
B : O
C : P
D : Q
E : R
F : S
G : T
H : U
I : V
J : W
K : X
L : Y
M : Z
N : A
O : B
P : C
Q : D
R : E
S : F
T : G
U : H
V : I
W : J
X : K
Y : L
Z : M
[ : [
\ : \
] : ]
^ : ^
_ : _
` : `
a : n
b : o
c : p
d : q
e : r
f : s
g : t
h : u
i : v
j : w
k : x
l : y
m : z
n : a
o : b
p : c
q : d
r : e
s : f
t : g
u : h
v : i
w : j
x : k
y : l
z : m
{ : {
| : |
} : }
~ : ~
Test cases
Test cases are in the format "input string" : "output string"
.
"gnat irk terra" : "tang vex green"
"2468" : "7913"
"#%&@,.:;?" : "#%&@,.:;?"
"Rot13.5 & Ebg68.0" : "Ebg68.0 & Rot13.5"
Explanations are optional, but I'm more likely to upvote answers that have one.
[Python 3], 145 bytes …
2y ago
Vyxal, 16 bytes ``` kakAkdW₌ …
2y ago
Stax, 15 bytes ⌐♪aù¢φσX▀┼╜ …
2y ago
[Bash], 31 bytes tr …
2y ago
4 answers
Python 3, 145 bytes
lambda s:[dict({chr(i+c):chr((i+13)%26+c)for i in range(26)for c in(65,97)},**{chr(i+48):chr((i+5)%10+48)for i in range(10)}).get(c,c)for c in s]
Generates and concatonates 2 dicts:
{chr(i+c):chr((i+13)%26+c)for i in range(26)for c in(65,97)}
-> {'A': 'N', 'a': 'n', 'B': 'O', 'b': 'o', 'C': 'P', 'c': 'p', 'D': 'Q', 'd': 'q', 'E': 'R', 'e': 'r', 'F': 'S', 'f': 's', 'G': 'T', 'g': 't', 'H': 'U', 'h': 'u', 'I': 'V', 'i': 'v', 'J': 'W', 'j': 'w', 'K': 'X', 'k': 'x', 'L': 'Y', 'l': 'y', 'M': 'Z', 'm': 'z', 'N': 'A', 'n': 'a', 'O': 'B', 'o': 'b', 'P': 'C', 'p': 'c', 'Q': 'D', 'q': 'd', 'R': 'E', 'r': 'e', 'S': 'F', 's': 'f', 'T': 'G', 't': 'g', 'U': 'H', 'u': 'h', 'V': 'I', 'v': 'i', 'W': 'J', 'w': 'j', 'X': 'K', 'x': 'k', 'Y': 'L', 'y': 'l', 'Z': 'M', 'z': 'm'}
for ROT13
{chr(i+48):chr((i+5)%10+48)for i in range(10)}
-> {'0': '5', '1': '6', '2': '7', '3': '8', '4': '9', '5': '0', '6': '1', '7': '2', '8': '3', '9': '4'}
for ROT5
It then gets the corresponding item from the concatonated dicts for each character in the input string.
Inputs as a string, outputs as a list
0 comment threads