substitution Cipher

Hi everyone, I am a complete novice to C coding and Programming. I have the task below and I have absolutely no idea where to start.
I am quite limited for time and I am totally stuck.
I can’t begin to explain how difficult I find this; books etc. just make matters worse not better.
If there is anyone out there who would be willing to either guide me through this, or at least point me in the right direction, I would be extremely grateful.
I need to create a program that encrypts plain text via a substitution cipher
The string to be used as the cipher key has to be between two to sixteen characters and contain only letters a through to z with no duplicates
The string used for the encryption (the plain text) has to be between four and two hundred and fifty-six characters and contain only letters a through to z in lower case plus spaces
X = the current position within the cipher key. X = 1 is the start point.

The method to encrypt will require these steps
01: Character at point X in the cipher key is the target value
02: Character at point X+1 in the cipher key = substitution value
03: If X is the last character in the cipher key, substitute value is the first character of the cipher key
04: All instances of the target value should be replaced with the substitution value, in the plain text
05: X should be increased by one and the process should be repeated until at the end of the cipher key
The following input has to be read by the program
Line ONE of the input = numeric digit or digits the gives the length of the cipher key
Line TWO of the input = cipher key text
Line THREE of the input = numeric digit or digits that give the length of the plain text
LINE FOUR of the input = the plain text that is to be encrypted
The Code / Program has to output the following information
The Step Number, example = if the cipher key is 3 then the output has to show steps one, two and three of the substitution
Both Target and Substitution values for each step
The text in encrypted format at each step of the substitution
Hello richard apps,

I have not covered every aspect of the program yet, but I have a couple of suggestions to get you started.

1. Include the header file "<string>" to work with the strings. Then you might define variables like:
std::string key;  // <--- The cypher key.
std::string input;  // <--- User input string to convert. 

With this you can access each element of the strings likekey[0]. Keep in mind C, C++ along with some other languages are zero based, so accessing something like a string, array, vector and some other array type containers start at zero not one. You will also have to be careful when using something like [index + 1] as a subscript because you can easily go past the end of the array which can crash the program.

2. Include the header file "<cctype>" to use the functions "std::tolower()" and "std::toupper()" to change the case of a letter. If no change is needed nothing happens.

3. Final suggestion is to break down everything into smaller steps and work on small pieces at a time. And the more you plan and use a flowchart or pseudo code to work with the easier it is to write the final code.

Hope that helps for now,

you can do it with an algorithm and all but for these I like to just make a lookup table.
populate the lookup with the value to replace, eg if you want to replace 'a' with '+' then table['a'] = '+'.
then the replacement is simply yourstring[i] = table[yourstring[i]];
and its done.
decrypt is done by having the reverse lookup table.

this may defeat the intent of your exercise; this is just the direct 5 lines of code get it done solution.

fun little assignment you got there. Try things out! Even tiny incremental changes like successfully grabbing user input and printing out the string (without changing it), and only then think about changing it. Don't panic; learning by doing is the best.
Registered users can post here. Sign in or register to post.