在 C++ 中隱藏字串在二進位制程式碼中的最佳方式?
這裡我們將看到如何將一些字串隱藏到一些二進位制程式碼中(此處二進位制程式碼以十六進位制數表示)。
方法很簡單。我們可以使用 string stream 將十進位制數轉換為十六進位制數。現在從字串中,我們將讀取每個字元,並獲取其 ASCII 值,這些 ASCII 值將轉換為十六進位制值。然後我們可以逐個打印出來。
示例
#include<iostream> #include<sstream> using namespace std; string dec_to_hex(int decimal){ //function is used to convert decimal to hex stringstream my_ss; my_ss << hex << decimal; return my_ss.str(); } main(){ string my_string = "This is a sample text"; for(int i = 0; i<my_string.length(); i++){ cout << dec_to_hex(my_string.at(i)) << " "; } }
輸出
54 68 69 73 20 69 73 20 61 20 73 61 6d 70 6c 65 20 74 65 78 74
廣告