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

Macros

#define ull   unsigned long long
 

Functions

pair< ull, ullgetRC (ull len)
 
int main ()
 

Macro Definition Documentation

#define ull   unsigned long long

Function Documentation

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