0

Hey guys, I am trying to figure out how to do a double transposition cipher.
This is what I have so far to take in a string and then put that string a 2x2 array of a fixed size that I made. I have the key that I want to use for the new 2x2 array, but I don't know how to implement it. Any ideas to help me figure it out? I want to do the work on my own, but helpful hints could really help me out

void transPosition(string b)
{
    int key[7] = {4,3,1,2,5,6,7};
    //gives d the size of the key
    int d = sizeof(key) / sizeof(key[0]);

    char matrix[4][7];
    //this loop will put the string in a 2x2 char array
    for(unsigned int i = 0; i < b.length(); i++)
    {
        matrix[i/d][i%d] = b[i];
    }

//just to check, we use this loop
//to see if the array has the letters
//in order from the string
    for(int i = 0; i < 4; i++)
    {
        for(int j = 0; j < 7; j++)
        {
            cout << matrix[i][j];
        }
        cout << endl;
    }
}
2
Contributors
2
Replies
23
Views
2 Years
Discussion Span
Last Post by TheFearful
0

I only need one key and let's say the plaintext is

{HELLOWO
 RLDWXYZ}

And the key is

{4,3,1,2,5,6,7}

The cipher text now looks like

 {LDLWELH
  ROXWYOZ}

And then we would do that a second time with the same key.

Edited by TheFearful

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.