How can I make this program where..

Write a simple encryption program using string functions which apply the substitution method. Explain the program by parts. Here is the given substitution table:
Substitution table:
A = *
E = $
I = /
O = +
U = -

Sample:
Enter message: meet me now
Encrypted message: m$$t m$ n+w

I can make use of strings...strcpy,puts, gets, strlen, strcat, strlwr, strupr, strrev, strcmp, strcmpi?
It is really simple:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
  char message[1000];
  gets(message);
  for(int i = 0; message[i] != 0; i++)
  {
    if((message[i] == 'A') || (message[i] == 'a'))
      message[i] = '*';
    else if((message[i] == 'E') ...
..
  }
  puts(message);
  return 0;
}

You can Search this site for strcpy etc. and the required header and example of how to use them
Last edited on
Don't ever use gets(). It was removed from C for a reason.
man wrote:
Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security.
Use fgets() instead
I would have rather said: Don't ever do other people's homework.
Especially when he already has other fools doing the same work for him here: http://cplusplus.com/forum/general/73673/

Not even in a different forum!?!
SORRY i dont really understand...my prof doesnt really teach...he gives us codes and examples and gives us these things and expects us to create something by our selves
hey but i tried making my own here

#include <cstdlib>
#include <iostream>
#include <string.h>
#define PAUSE system("PAUSE");

using namespace std;

bool vowel(char c){
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'|| c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
return true;

return false;
}
char replace(char c)
{
switch(c)
{
case 'a': case 'A': return '*';
case 'e': case 'E': return '$';
case 'i': case 'I': return '/';
case 'o': case 'O': return '+';
case 'u': case 'U': return '-';
}
}
int main(int argc, char *argv[])
{
char input[100];
cout<<"Input phrase :";
gets(input);

for(int i=0; i <100; i++){
if(vowel(input[i]))
input[i]=replace(input[i]);
}

puts(input);
PAUSE

return EXIT_SUCCESS;
}
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
#include <iostream>
#include <sstream>
using namespace std;

string encrypt(string s) {
    for (int i = 0; i < s.length(); i++) {
        switch(s[i]) {
            case 'a': s[i] = '*'; break;
            case 'e': s[i] = '$'; break;
            case 'i': s[i] = '/'; break;
            case 'o': s[i] = '+'; break;
            case 'u': s[i] = '-'; break;
        }
    }
    return s;
}

int main() {

    string sentence;
    cout << "Enter a string: ";
    getline(cin, sentence);
    cout << "Encrypted string is: " << encrypt(sentence) << endl;
    system("pause");

}
Last edited on
Topic archived. No new replies allowed.