Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bfed18d

Browse files
Created encryption.js
1 parent 2734e67 commit bfed18d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎Implementation/encryption.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
function encryption(s) {
2+
var strArr=[];
3+
var len=0;
4+
//Remove spaces
5+
for(var i=0; i<s.length; i++){
6+
if(s.charAt(i)!=' '){
7+
strArr.push(s.charAt(i));
8+
len++;
9+
}
10+
}
11+
var row= Math.floor(Math.sqrt(len));
12+
var column= Math.ceil(Math.sqrt(len));
13+
while((row*column)<len){
14+
//Column has the max value so increament the row
15+
row++;
16+
}
17+
var arrMatrix= new Array(row);
18+
for(var i=0; i<row; i++){
19+
arrMatrix[i]= new Array(column);
20+
}
21+
var count=0;
22+
for(var i=0; i<row; i++){
23+
for(var j=0; j<column; j++){
24+
if(count==len){
25+
break;
26+
}
27+
else{
28+
arrMatrix[i][j]= strArr[count];
29+
count++;
30+
}
31+
}
32+
}
33+
var finalArr=[];
34+
for(var i=0; i<column; i++){
35+
for(var j=0; j<row; j++){
36+
if(arrMatrix[j][i]!=undefined){
37+
finalArr.push(arrMatrix[j][i]);
38+
}
39+
}
40+
finalArr.push(" ");
41+
}
42+
var finalStr=finalArr.join("");
43+
return finalStr;
44+
}
45+
46+
function main() {
47+
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
48+
49+
const s = readLine();
50+
51+
let result = encryption(s);
52+
53+
ws.write(result + "\n");
54+
55+
ws.end();
56+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /