• + 0 comments
    function encryption(s: string): string {
        const newS = s.replace(/ /g, "");
        let result = "";
    
        let rows = Math.floor(Math.sqrt(newS.length));
        let columns = Math.ceil(Math.sqrt(newS.length));
    
        if (rows * columns < newS.length) {
            rows = Math.max(rows, columns);
            columns = Math.max(rows, columns);
        }
    
        for (let i = 0; i < columns; i++) {
            for (let j = 0; j < rows; j++) {
                if (i + columns * j < newS.length) {
                    result += newS[i + columns * j];
                }
            }
            
            result += " ";
        }
    
        return result;
    }