Some kind of encryption in C++ It's my university task. Can I get some opinions on it?

#include &lt;iostream&gt;
#include &lt;vector&gt;


using namespace std;

string toBinary(short n) {
   string r;
   while(n != 0) {
      r = ( n % 2 == 0 ? "0" : "1" ) + r;
      n /= 2;
   }
   return r;
}

int has_even_parity(int c) {
   int k = 0;
   if (c != 0)
      k++;
if ((c &amp; 0x2) &gt;&gt; 1 == 1)
    k++;
if ((c &amp; 0x4) &gt;&gt; 2 == 1)
    k++;
if ((c &amp; 0x8) &gt;&gt; 3 == 1)
    k++;
if ((c &amp; 0x10) &gt;&gt; 4 == 1)
    k++;
if ((c &amp; 0x20) &gt;&gt; 5 == 1)
    k++;
if ((c &amp; 0x40) &gt;&gt; 6 == 1)
    k++;
if ((c &amp; 0x80) &gt;&gt; 7 == 1)
    k++;
 return k % 2;
}

char decode(short int a) {
  char result;
  unsigned short int mask = 0b0111111110000000;
  return (char)((a &amp; mask) &gt;&gt; 7);
}

int main() {
short int result[64];
string str;
vector&lt;string&gt; text_list;

for (int i = 0; i &lt; 8; i++) {
    getline(cin, str);
    text_list.push_back(str);
}
cout &lt;&lt; endl;
int k = 0;

for (int i = 0; i &lt; text_list.size(); i++) {
    string l = "";
    for (int j = 0; j &lt; text_list[i].size(); j++) {
        short int c_ = text_list[i][j];
        short int l_ = 0b0000000;
        c_ = l_ | c_;
        result[k] = (short) has_even_parity(c_);
        result[k] = result[k] &lt;&lt; 8;
        result[k] = result[k] | c_;
        result[k] = result[k] &lt;&lt; 1;
        c_ = (short) (has_even_parity(i) ^ has_even_parity(j));

        result[k] = result[k] | c_;
        result[k] = result[k] &lt;&lt; 3;
        result[k] = (short) (result[k] | i);

        result[k] = result[k] &lt;&lt; 3;
        result[k] = (short) (result[k] | j);

        l += decode(result[k]);
        k++;
    }
    cout &lt;&lt; l &lt;&lt; endl;
}

return 0;
}


I have input as text 8 letters x 8 lines, 2 bytes for one letter.


In bit 0-2 number of line
In bit 3-5 number of position in line
In bit 6 parity bit of 1) and 2)
In bit 7-14 ASCII code of letter
In bit 15 parity bit of 4)


And after, decode letter.
using namespace std; is a bad habit. It's not that tedious to write std:: a few times and you get less name collisions on things you define.



Your indentation is inconsistent. This makes it difficult to follow the control flow. 



The even parity can be discovered with repeated xors:

int has_even_parity(int c) {
   c ^= c &gt;&gt; 4;
   c ^= c &gt;&gt; 2;
   c ^= c &gt;&gt; 1;
   return ! (c&amp;1);
}




short int l_ = 0b0000000;
c_ = l_ | c_;


This doesn't do anything. 



I suggest adding some underscores in the binary literals to group the digits:

unsigned short int mask = 0b0111_1111_1000_0000;


This makes it easier to tell at a glance that there are 7 zeros at the end and that you meant for them to be there. Though once you are more comfortable with hexadecimal then 0x7f80 is just as clear.