-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.cpp
More file actions
55 lines (41 loc) · 731 Bytes
/
Copy pathencryption.cpp
File metadata and controls
55 lines (41 loc) · 731 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void encryption(string s)
{
int x = floor(sqrt(s.length()));
int y = ceil(sqrt(s.length()));
if(x*y < s.length())
x++;
char grid[x][y];
int k=0;
for (int i = 0; i < x; ++i)
for (int j = 0; j < y; ++j)
{
if (k +1 > s.length())
grid[i][j] = '-';
else
grid[i][j] = s[k];
k++;
}
for (int i = 0; i < y; ++i)
{
for (int j = 0; j < x; ++j)
{
if(grid[j][i] != '-')
cout<<grid[j][i];
}
cout<<" ";
}
cout<<endl;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
string s;
cin>>s;
encryption(s);
return 0;
}