Function call

For this assignment, I have to take a user's input and keyword and encrypt it into a Vigenere cipher. The encryption coding is done along with pretty much everything else, but I'm having trouble figuring out how to call the function.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <map>

using namespace std;

string Encode(string msg, string keyword, map<int,char> letters) //this is the encryption function
{
        string retmsg = "";

      for (int i = 0; i<msg.length(); i++)
      {
                char msgch = toupper(msg[0]);
                char keych = toupper(keyword[0]);

                int msgplace = msgch % 64;
                int keyplace = keych % 64;

                int place = keyplace + msgplace - 1;

                if (place > 26){
                        place = place - 26;
                }

                retmsg = letters[place];     
	}
        return retmsg;
}

int main()
{
        map<int, char> letters;

        letters[1] = 'A'; letters[14] = 'N';
        letters[2] = 'B'; letters[15] = 'O';
        letters[3] = 'C'; letters[16] = 'P';
        letters[4] = 'D'; letters[17] = 'Q';
        letters[5] = 'E'; letters[18] = 'R';
        letters[6] = 'F'; letters[19] = 'S';
        letters[7] = 'G'; letters[20] = 'T';
        letters[8] = 'H'; letters[21] = 'U';
        letters[9] = 'I'; letters[22] = 'V';
        letters[10] = 'J'; letters[23] = 'W';
        letters[11] = 'K'; letters[24] = 'X';
        letters[12] = 'L'; letters[25] = 'Y';
        letters[13] = 'M'; letters[26] = 'Z';

        string strMsg = "";
        cout << "Enter Message: ";
        cin >> strMsg;

        string keyword = "";
        cout << "Enter keyword: ";
        cin >> keyword;

        int mult = (strMsg.length()/keyword.length());
        for(int i=0;i<mult;i++){
                keyword += keyword;
        }
        keyword = keyword.substr(0,strMsg.length());  

		cout << Encode(strMsg, keyword,);
		cin.get();

        return 0;
}


The problem is there towards the bottom at cout << Encode. There aren't enough arguments in the function call, but I'm not sure what the third argument should be. Once I figure out what it is, then it should in theory output the encrypted text.


tl,dr; I need a third argument for my function call and I don't know what it is.
letters

p.s.
1
2
3
4
5
6
7
8
9
10
11
12
13
        letters[1] = 'A'; letters[14] = 'N';
        letters[2] = 'B'; letters[15] = 'O';
        letters[3] = 'C'; letters[16] = 'P';
        letters[4] = 'D'; letters[17] = 'Q';
        letters[5] = 'E'; letters[18] = 'R';
        letters[6] = 'F'; letters[19] = 'S';
        letters[7] = 'G'; letters[20] = 'T';
        letters[8] = 'H'; letters[21] = 'U';
        letters[9] = 'I'; letters[22] = 'V';
        letters[10] = 'J'; letters[23] = 'W';
        letters[11] = 'K'; letters[24] = 'X';
        letters[12] = 'L'; letters[25] = 'Y';
        letters[13] = 'M'; letters[26] = 'Z';
could have been done with a simple for loop.
Last edited on
I tried letters, but it doesn't output the encryption properly
Also, how could I do that with a for loop? I tried something like that initially (based this off a caesar cipher program) but couldn't get it to compile
I tried letters, but it doesn't output the encryption properly

Then you probably have a problem with the encryption routine. :)

Lines 21-22: place can be bigger than 52 (can be 125) so that after subtracting 26, place will still be bigger than 26 and not found in the map.

Line 25: You're setting retmsg equal to a single character each time through the loop. After completing the loop retmsg will contain only the the last character translated (assuming it was found).

Also, how could I do that with a for loop
1
2
    for (int i=0; i<26; i++)
        letters[i+1] = 'A' + i;

Last edited on
Topic archived. No new replies allowed.