MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / generate_displayable_code

Function generate_displayable_code

src/dpp/voice/enabled/displayable_code.cpp:32–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30namespace dpp {
31
32std::string generate_displayable_code(const std::vector<uint8_t> &data, size_t desired_length = 30, size_t group_size = 5) {
33
34 if (data.empty()) {
35 return "";
36 }
37
38 const size_t group_modulus = std::pow(10, group_size);
39 std::stringstream result;
40
41 for (size_t i = 0; i < desired_length; i += group_size) {
42 size_t group_value{0};
43
44 for (size_t j = group_size; j > 0; --j) {
45 const size_t next_byte = data.at(i + (group_size - j));
46 group_value = (group_value << 8) | next_byte;
47 }
48 group_value %= group_modulus;
49 result << std::setw(group_size) << std::setfill('0') << std::to_string(group_value) << " ";
50 }
51
52 return result.str();
53}
54
55}

Callers 2

get_user_privacy_codeMethod · 0.85
update_ratchetsMethod · 0.85

Calls 2

to_stringFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected