-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (31 loc) · 761 Bytes
/
index.js
File metadata and controls
38 lines (31 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function encryption(s) {
let strLength = s.length;
let row = Math.floor(Math.sqrt(strLength));
let column = Math.ceil(Math.sqrt(strLength));
if (row + column <= strLength) {
row = column;
}
let columns = new Array(column);
for (let i = 0; i < row; i++) {
columns[i] = [];
}
let counter = 0;
for (let i = 0; i < row; i++) {
for (let y = 0; y < column; y++) {
columns[i][y] = s[counter++];
}
}
let finish = [];
for (let i = 0; i < columns.length; i++) {
let str = "";
for (let y = 0; y < row; y++) {
if (columns[y][i] != undefined) {
str += columns[y][i];
}
}
finish.push(str);
}
console.log(finish.join(" "));
}
// encryption("haveaniceday");
encryption("chillout");