Change encoded base from hexadecimal to base 32
This commit is contained in:
@@ -4,7 +4,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
namespace code {
|
#include <base-helpers.hpp>
|
||||||
|
|
||||||
|
namespace connect_code {
|
||||||
namespace { /* Since these are internal function, I have wrapped them in an anonymous namespace, to prevent outside access to them */
|
namespace { /* Since these are internal function, I have wrapped them in an anonymous namespace, to prevent outside access to them */
|
||||||
|
|
||||||
/* Tokenizes a string, based on the given delimiter */
|
/* Tokenizes a string, based on the given delimiter */
|
||||||
@@ -49,16 +51,10 @@ namespace code {
|
|||||||
std::string encode(std::string address, std::string port) {
|
std::string encode(std::string address, std::string port) {
|
||||||
/* Convert the address to decimal, and convert that to hex */
|
/* Convert the address to decimal, and convert that to hex */
|
||||||
std::string addr_coded = dotted_dec_to_dec(address);
|
std::string addr_coded = dotted_dec_to_dec(address);
|
||||||
std::stringstream stream;
|
addr_coded = base_convert(addr_coded, 10, 32);
|
||||||
stream << std::hex << std::stoul(addr_coded, 0, 10);
|
|
||||||
addr_coded = stream.str();
|
|
||||||
|
|
||||||
stream.str("");
|
|
||||||
|
|
||||||
/* Convert the port to hex */
|
/* Convert the port to hex */
|
||||||
stream << std::hex << std::stoul(port, 0, 10);
|
std::string port_coded = base_convert(port, 10, 32);
|
||||||
std::string port_coded = stream.str();
|
|
||||||
|
|
||||||
std::string ret_val = addr_coded + "_" + port_coded;
|
std::string ret_val = addr_coded + "_" + port_coded;
|
||||||
|
|
||||||
return ret_val;
|
return ret_val;
|
||||||
@@ -72,8 +68,8 @@ namespace code {
|
|||||||
std::string port = result[1]; /* Port (in base 16) */
|
std::string port = result[1]; /* Port (in base 16) */
|
||||||
|
|
||||||
/* Base 16 to base 10 - These lines convert the string to a base 10 number, and convert the result back into a string */
|
/* Base 16 to base 10 - These lines convert the string to a base 10 number, and convert the result back into a string */
|
||||||
address = std::to_string(std::stoul(address, 0, 16));
|
address = std::to_string(std::stoul(address, 0, 32));
|
||||||
port = std::to_string(std::stoul(address, 0, 10));
|
port = std::to_string(std::stoul(address, 0, 32));
|
||||||
|
|
||||||
/* Convert decimal address to dotted decimal */
|
/* Convert decimal address to dotted decimal */
|
||||||
address = dec_to_dotted_dec(address);
|
address = dec_to_dotted_dec(address);
|
||||||
@@ -83,4 +79,6 @@ namespace code {
|
|||||||
ret_val.push_back(port);
|
ret_val.push_back(port);
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user