help on solving problem

hello
i am currently writing a program for permutation cipher encryption and decryption
how it works:
keyword :
hello

then we write our plaintext under the keyword as such:

hello
ihave
aprob
lem

then we alphabetically organize the keyword
ehllo

and write the letters coresponding to each keyword letter under them

ehllo
eiave
barob
lm

and now the cipher text is just reading all the lines
eiave barob lm

now the function to encrypt this i have made,but the problem i'm having is with decryption

the current funcion i have for decrypting is


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
std::string sortedKey = key;
 std::sort ( sortedKey.begin(), sortedKey.end() );
int letIndex=0;
int update=0;
//num of rows is the rows needed to fill out the plaintext in the keyword
for(int i = 0 ; i < NumOfRows;i++){
    std::string sortedKeyCopy = sortedKey ;

    for(char c : key){

        size_t io = sortedKeyCopy.find(c);


        int index = (int) io;
            index+=update;

         if(index >= t ){

            continue;

        }
        sortedKeyCopy[io]=' ';
//raw text is the encrypted text we're trying to decrypt 
        decryptedText.push_back(rawText[index]);


    }

update+=keyLength;

}

but this code messes up the decryption in the final letters
i have no idea why,does anyone know?
Last edited on
Topic archived. No new replies allowed.