• + 0 comments

    JavaScript

    function encryption(s) {
        let columns = Math.ceil(Math.sqrt(s.length));
        let result = Array(columns).fill("");
        for (let i = 0; i < s.length; i++) {
            result[(i + 1) % columns] += s[i];
        }
        result.push(result.shift());
        return result.join(" ");
    }