A
A
Alexander Petrenko2018-03-13 02:57:54
JavaScript
Alexander Petrenko, 2018-03-13 02:57:54

How to write atbash cipher in 3 lines?

Hello, I would like to look at the atbash cipher code using recursion.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-03-13
@Gelisore

Python, example from here .

def atbash(s):
    abc = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
    return s.translate(str.maketrans(
        abc + abc.upper(), abc[::-1] + abc.upper()[::-1]))

print(atbash("Привет Мир!"))

If you need exactly recursion, and even in javascript, you can do it this way, but in my opinion it will be complete shit:
const abc = "abcdefghijklmnopqrstuvwxyz", t = {};
for (let i = 0, j = abc.length; j;) t[abc.charAt(i++)] = abc.charAt(--j);
const atbash = s => s ? (t[s.charAt(0)] || s.charAt(0)) + atbash(s.slice(1)) : s;

console.log(atbash("hello, world!"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question