Cryptography  1.0
Implementation of Cryptography Algorithms
Macros | Functions
decr_routeCipher.cpp File Reference
#include <iostream>
#include <bits/stdc++.h>
Include dependency graph for decr_routeCipher.cpp:

Macros

#define ull   unsigned long long
 

Functions

int main ()
 

Macro Definition Documentation

#define ull   unsigned long long

Function Documentation

int main ( )
8  {
9  string enc_message = "", str;
10  ull len ,i ,j ,k ,l, row, col;
11  string enc_matrix[100];
12  i=0;
13  getline(cin,str);
14  istringstream istream(str);
15  for(string s; istream >> s;) {
16  enc_matrix[i] = s;
17  i++;
18  }
19  row = i;
20  col = enc_matrix[0].size();
21  //cout << row << " " << col <<endl;
22  pair<ull,ull> dim = make_pair(row,col);
23  ull c_count = 0, max_r = dim.first-1, min_c = 0, min_r = 0, max_c = dim.second-1;
24  len = row * col;
25  //cout << min_r <<" " << max_r <<" " << min_c << " " << max_c <<endl;
26  while(c_count < len) {
27  for(i = min_r; i <= max_r;++i) {
28  if(c_count == len) {break;}
29  enc_message+= enc_matrix[i][max_c];
30  c_count ++;
31  }
32 
33  //cout << c_count << endl;
34  for(j = max_c-1;j>=min_c;--j) {
35  if(c_count == len) {break;}
36  enc_message+= enc_matrix[max_r][j];
37  ++c_count;
38  if(j == min_c){ break;}
39 
40  }
41  //cout << c_count << endl;
42  for(k = max_r-1;k>=min_r;--k) {
43  if(c_count == len) {break;}
44  enc_message+= enc_matrix[k][min_c];
45  ++c_count;
46  if(k == min_r){ break;}
47  }
48  //cout << c_count << endl;
49  for(l = min_c + 1;l<=max_c -1;++l) {
50  if(c_count == len) {break;}
51  enc_message+= enc_matrix[min_r][l];
52  c_count ++;
53  }
54  //cout << c_count << endl;
55  ++min_c;
56  ++min_r;
57  --max_r;
58  --max_c;
59  }
60  cout << enc_message <<endl;
61  return 0;
62 }
#define ull
Definition: decr_routeCipher.cpp:7