I was doing a simple c++ chat and i wanted to encrypt the messages with a simple made code.
So i thought it would be like chars a-x and then it would replace them for example a -11.
So it would need to
- Split the message into chars
- Change the chars into number
- Put them back in the right order.
So does anyone knows how to do it?
Thanks 🙂
std::stringwill store arbitrary values ofchar, and let you access individual characters quite easily. For encryption, however, you might prefer to work withunsigned char, which is pretty easy too —std::stringis just a typedef forstd::basic_string<char>, butstd::basic_string<unsigned char>is pretty easy to manage.It sounds like what you want is on the order of a Ceaser cipher, though it’s easiest if you just “encrypt” everything, rather than just letters.
Then to “decrypt” you’d just do the opposite: