forked from nayyyhaa/C-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.cpp
More file actions
69 lines (41 loc) · 1.54 KB
/
Encryption.cpp
File metadata and controls
69 lines (41 loc) · 1.54 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Name: Neha Gupta
// Email-id: nehaguptang.ng@gmail.com
//Output Format -: Print the encoded message on one line as described.
//Sample Input :- haveaniceday
//Sample Output :- hae and via ecy
#include <bits/stdc++.h>
#include<string>
#include<cmath>
using namespace std;
string encryption(string s)
{
int length,sq,sq1,j;
string yo; //Resulatant string
length = s.length(); //to find length of inputed string
sq=sqrt(length);
if(sq*sq==length) //if length is perfect square then row size is equal to column size.
sq1=sq;
else //else increment the column length
sq1=sq+1;
for(int i=0;i<sq1;i++) //looping till the column length for output
{
j=i; //inner loop initilaisation
while(j<length) //looping till the length of input string
{
yo=yo+s.at(j); //adding element columnnwise present at location j
j=j+sq1; //columnwise addition
}
yo=yo+" ";
}
return yo; //return following result 'yo' as output.
}
int main() //main function of program
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
string result = encryption(s);
fout << result << "\n";
fout.close();
return 0;
}