Need help converting a C # method to C ++

I am a guy from C # who is desperately trying to learn C ++ and move the old code. So far, everything is in order, but the following method has guarded me. If anyone could give me some pointers (sorry for the pun), I would be grateful.

C # Method:

public static string crappyEncryption(String userKey) { StringBuilder eStr = new StringBuilder(); String key1 = "somehorriblelongstring"; String key2 = "someotherhorriblelongstring"; for (int i = 0; i < userKey.Length; i++) { eStr.Append(key2[key1.IndexOf(userKey[i])]); } return encodeTo64(eStr.ToString()); } 

encodeTo64 is a local method that I decided in C ++. This weird method (if you're interested) was a small encryption method that I came up with so that we can use the mobile cross platform for non-essential string encryption.

Thank you very much

+4
source share
1 answer

We will not give you all the code, but some pointers:

  • a StringBuilder can be replaced with std::stringstream .
  • a String is std::string
  • it has a method of length() , find() and operator[] .
  • std::stringstream has operator << for Append .
  • ToString - std::stringstream::str() .
  • you need to pass userKey by reference.

All concepts that you don’t understand are easy to find using google search.

+3
source

Source: https://habr.com/ru/post/1440406/


All Articles