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

Macros

#define ull   unsigned long long
 
#define pb   push_back
 

Functions

string fillBlanks (string s, ull l)
 
int main ()
 

Macro Definition Documentation

#define pb   push_back
#define ull   unsigned long long

Function Documentation

string fillBlanks ( string  s,
ull  l 
)
9  {
10  if(s.size() < l) {
11  while(s.size() != l) {
12  s += "!";
13  }
14  }
15  return s;
16 }
int main ( )
17  {
18  cout << "IMPLEMENTATION OF TRANSPOSITION CIPHER USING COLUMNAR TRANPOSITION" <<endl;
19  string key, str;
20  vector<string> message;
21  vector<string> enc_message;
22  ull i,j,len,key_len, order_size;
23  cin >> key;
24  key_len = key.size();
25  string temp_key = key;
26  getline(cin,str);
27  while(getline(cin, str)){
28  if(str.empty()){break;}
29  message.pb(str);
30  }
31  double time_taken = clock();
32 
33  len = message.size();
34  enc_message = message;
35  message[len - 1] = fillBlanks(message[len - 1], key_len);
36  for(i=0;i<len;i++) {
37  cout << message[i] <<endl;
38  }
39  /* Forming the key*/
40  vector<ull> ordered, unordered;
41  sort(temp_key.begin(), temp_key.end());
42  for(i=0;i<key_len;i++) {
43  ordered.pb(i+1);
44  }
45  order_size = ordered.size();
46  for(i=0;i<order_size;i++) {
47  for(j = 0;j<order_size;j++) {
48  if(temp_key[j] == key[i]) {
49  //cout << temp_key[j] << " Matched " << key[i]<<endl;
50  unordered.pb(j+1);
51  break;
52  }
53  }
54  }
55  /* Forming the encrypted message*/
56  for(i=0;i<key_len;i++) {
57  for(j=0;j<len;j++) {
58  enc_message[j][unordered[i] - 1] = message[j][ordered[i]-1];
59  }
60  }
61  for(i=0;i<key_len;i++) {
62  for(j=0;j<len;j++) {
63  cout<< enc_message[j][i];
64  }
65  cout << " ";
66  }
67  cout << endl;
68  time_taken = (clock() - time_taken)/CLOCKS_PER_SEC;
69  cout << time_taken <<endl;
70  return 0;
71 }
string fillBlanks(string s, ull l)
Definition: TransCipher.cpp:9
#define ull
Definition: TransCipher.cpp:7
key
Definition: DESKeygen.py:182