rot encrypt c++

so basically I need to create a encryption function using rot . The function shold not contain the string to be encrypted and should not contain a decryption function
it starts like this
#include "encrypt.h"


std::string encrypt (std::string text, int rot) {
and ends like this

return NULL;
}
I thoug in setting a int and putting ita a value and then put the rot or in putting a cin and then rot cout but it seem I cant get to a correct anwser and to write the code correctly.
closed account (o3hC5Di1)
Hi there,

It's not entirely clear to me what your question is exactly?
Would you perhaps be so kind as to rephrase and / or clarify it?

Now, there is something wrong in the code you gave:

std::string encrypt(std::string text, int rot) //return type is std::string

So how can the function return NULL?
If you want to alter the text directly, you need to pass the text in by reference:

std::string encrypt(std::string& text, int rot)

Hope that helps.

All the best,
NwN
you are right NwN the only information I have is this include
"encrypt.h"


string encrypt (string text, int rot) {

}
The function begins like that and I need to create a function that can encrypt different strings that I dont knoe and they should only encrypt the letter so the numbers,spaces,etc shoul remain the same.
closed account (o3hC5Di1)
Hi there,

The key thing to remember here is that every character in C++ is internally represented as a number, and can thus be treated as such. For an overview, please see this page: http://www.cplusplus.com/doc/ascii/

Now, the string will be passed into the function, you will have to look at every character, so you will need some sort of loop to access each character.

For every character, you check whether the character is a letter. If it is, you can just increase it by rot, the other function parameter.

Some hints:

- Individual characters of a string can be accessed as such: string[n], where n is a number representing the position of a letter in the string.
- http://www.cplusplus.com/reference/cctype/isalpha/

Please do let us know if you require any further help.

All the best,
NwN

The function shold not contain the string to be encrypted

I thoug in setting a int and putting ita a value and then put the rot or in putting a cin and then rot cout but it seem I cant get to a correct anwser and to write the code correctly.


no offense, but i don't understand what do you mean... seriously...
Topic archived. No new replies allowed.