Custom Cipher Language

I created a cipher type language a few days back along the lines of:a=o, b=d, c=v, ect. This "language" also has rules like "if a word ends with "k", it becomes "q" ect."

I'm trying to create a translator, simply to take what i type in a program and convert it to this ciphered language.

I'm familiar with programming language, but not so much with c++.

Here is a sample of what I have.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
  {
  string s = "The quick brown fox jumps over the lazy dog.";
  replace( s.begin(), s.end(), 'b', 'd' );
  replace( s.begin(), s.end(), 'd', 'x' );
  cout << s << endl;
  cin.get();
  return 0;
  }


My problem is, once the "b" is replaced by a "d" in line 9, that "d" can be replaced again by the next line, and so on. I was wondering if there was a way to replace a letter, and once it's been replaced, then it can't be changed again.

Also, I would like to be able to actually input what I want to be translated, but that is unknown to me as well...
1
2
std::transform( s.begin(), s.end(), s.begin(),
                []( char c ) { return ( (c == 'b' ? 'd' : ( c == 'd' ? 'x' : c ) ) ); } );


EDIT: To input a line of a text use std::getline()
Last edited on
The "if word ends with" rules require separate treatment though.
Topic archived. No new replies allowed.