Cryptogram Help!

I need some help with a cryptogram, where you match a letter to another letter. I'm a beginner's learner, so my attempt is fairly basic.

I can't seem to figure out the algorithm, but here's what I have. This is just the code where I need help with.

I have three vectors, one called origmessage, another called cryptmessage, and the last one called encryptmessage.

The origmessage has the sentence "I go to school" and the cryptmessage contains the cryptogram "abcdefgh" and the encryptmessage is the vector where I put in the encrypted message.

The encrypted message should be a bc dc efgcch

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
for(int i = 0; i < cryptmessage.size(); i++)
    {
      if(encryptmessage[i] == " ")
	{
	  encryptmessage[i] = cryptmessage[i];
	  cout << encryptmessage[i];
	}
      encryptmessage.push_back(cryptmessage[i]);
      for(int j = 1; j < cryptmessage.size(); j++)
	{
	  if(origmessage[i] == origmessage[j])
	    {
	      for(int k = 0; k < j - 1; j++)
		encryptmessage.push_back(" ");
	    }
	  encryptmessage.push_back(cryptmessage[i]);
	  cout << encryptmessage[i];
	}
    }
  for(int z = cryptmessage.size(); z < cryptmessage.size(); z++)
    {
      for(int h = 0; h < cryptmessage.size(); h++)
	if(origmessage[z] == origmessage[h])
	  {
	    for(int g = 0; g < h - 1; g++)
	      encryptmessage.push_back(" ");
	  }
	  encryptmessage.push_back(cryptmessage[z]);
	  cout << encryptmessage[z];
    }


I have one main for loop where it assigns each letter to its corresponding cryptogram, and another for loop where if it is done assigning each letter, it then checks the rest of the message and matches up the letter with the already assigned cryptogram. But, I'm not sure if this is right? Can anybody help?

Topic archived. No new replies allowed.