Change encoded base from hexadecimal to base 32

master
Aadhavan Srinivasan 8 months ago
parent 74b9ae5fe8
commit fbea42df25

@ -4,7 +4,9 @@
#include <vector>
#include <cstdint>
#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 */
/* Tokenizes a string, based on the given delimiter */
@ -49,16 +51,10 @@ namespace code {
std::string encode(std::string address, std::string port) {
/* Convert the address to decimal, and convert that to hex */
std::string addr_coded = dotted_dec_to_dec(address);
std::stringstream stream;
stream << std::hex << std::stoul(addr_coded, 0, 10);
addr_coded = stream.str();
stream.str("");
addr_coded = base_convert(addr_coded, 10, 32);
/* Convert the port to hex */
stream << std::hex << std::stoul(port, 0, 10);
std::string port_coded = stream.str();
std::string port_coded = base_convert(port, 10, 32);
std::string ret_val = addr_coded + "_" + port_coded;
return ret_val;
@ -72,8 +68,8 @@ namespace code {
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 */
address = std::to_string(std::stoul(address, 0, 16));
port = std::to_string(std::stoul(address, 0, 10));
address = std::to_string(std::stoul(address, 0, 32));
port = std::to_string(std::stoul(address, 0, 32));
/* Convert decimal address to dotted decimal */
address = dec_to_dotted_dec(address);
@ -83,4 +79,6 @@ namespace code {
ret_val.push_back(port);
return ret_val;
}
}

Loading…
Cancel
Save