1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include <iostream> #include <cstdint> #include <iomanip> #include <vector> #include <tuple> #include <cassert>
using hash_tuple_t = std::tuple<std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t>;
hash_tuple_t http_hash_to_qvod_hash(hash_tuple_t http_hash_tuple) { auto http2qvod = [](std::uint32_t hash, int rol) -> std::uint32_t { std::uint32_t inter_value = hash ^ 0x694A873C; inter_value = ((inter_value & 0xff000000) >> 8) | ((inter_value & 0x00ff0000) << 8) | ((inter_value & 0x0000ff00) >> 8) | ((inter_value & 0x000000ff) << 8); inter_value = (inter_value << rol) | (inter_value >> (32 - rol)); return ((inter_value & 0xff000000) >> 8) | ((inter_value & 0x00ff0000) << 8) | ((inter_value & 0x0000ff00) >> 8) | ((inter_value & 0x000000ff) << 8); }; std::uint32_t qvod_hash0 = http2qvod(std::get<0>(http_hash_tuple), 1); std::uint32_t qvod_hash1, qvod_hash2, qvod_hash3, qvod_hash4; std::uint32_t key = qvod_hash0 & 0x00000F00; switch(key) { case 0x00000000: case 0x00000400: case 0x00000800: case 0x00000C00: qvod_hash1 = http2qvod(std::get<1>(http_hash_tuple), 1); qvod_hash2 = http2qvod(std::get<2>(http_hash_tuple), 1); qvod_hash3 = http2qvod(std::get<3>(http_hash_tuple), 1); qvod_hash4 = http2qvod(std::get<4>(http_hash_tuple), 1); break; case 0x00000100: case 0x00000500: case 0x00000900: case 0x00000D00: qvod_hash1 = http2qvod(std::get<1>(http_hash_tuple), 9); qvod_hash2 = http2qvod(std::get<2>(http_hash_tuple), 1); qvod_hash3 = http2qvod(std::get<3>(http_hash_tuple), 9); qvod_hash4 = http2qvod(std::get<4>(http_hash_tuple), 1); break; case 0x00000200: case 0x00000600: case 0x00000A00: case 0x00000E00: qvod_hash1 = http2qvod(std::get<1>(http_hash_tuple), 9); qvod_hash2 = http2qvod(std::get<2>(http_hash_tuple), 7); qvod_hash3 = http2qvod(std::get<3>(http_hash_tuple), 1); qvod_hash4 = http2qvod(std::get<4>(http_hash_tuple), 9); break; default: qvod_hash1 = http2qvod(std::get<1>(http_hash_tuple), 9); qvod_hash2 = http2qvod(std::get<2>(http_hash_tuple), 7); qvod_hash3 = http2qvod(std::get<3>(http_hash_tuple), 8); qvod_hash4 = http2qvod(std::get<4>(http_hash_tuple), 1); break; } return std::make_tuple(qvod_hash0, qvod_hash1, qvod_hash2, qvod_hash3, qvod_hash4); }
hash_tuple_t qvod_hash_to_http_hash(hash_tuple_t qvod_hash_tuple) { auto qvod2http = [](std::uint32_t hash, int rol) -> std::uint32_t { std::uint32_t inter_value = ((hash & 0xff000000) >> 8) | ((hash & 0x00ff0000) << 8) | ((hash & 0x0000ff00) >> 8) | ((hash & 0x000000ff) << 8); inter_value = (inter_value >> rol) | (inter_value << (32 - rol)); inter_value = ((inter_value & 0xff000000) >> 8) | ((inter_value & 0x00ff0000) << 8) | ((inter_value & 0x0000ff00) >> 8) | ((inter_value & 0x000000ff) << 8); return inter_value ^ 0x694A873C; }; std::uint32_t qvod_hash0 = std::get<0>(qvod_hash_tuple); std::uint32_t http_hash0 = qvod2http(qvod_hash0, 1); std::uint32_t http_hash1, http_hash2, http_hash3, http_hash4; std::uint32_t key = qvod_hash0 & 0x00000F00; switch(key) { case 0x00000000: case 0x00000400: case 0x00000800: case 0x00000C00: http_hash1 = qvod2http(std::get<1>(qvod_hash_tuple), 1); http_hash2 = qvod2http(std::get<2>(qvod_hash_tuple), 1); http_hash3 = qvod2http(std::get<3>(qvod_hash_tuple), 1); http_hash4 = qvod2http(std::get<4>(qvod_hash_tuple), 1); break; case 0x00000100: case 0x00000500: case 0x00000900: case 0x00000D00: http_hash1 = qvod2http(std::get<1>(qvod_hash_tuple), 9); http_hash2 = qvod2http(std::get<2>(qvod_hash_tuple), 1); http_hash3 = qvod2http(std::get<3>(qvod_hash_tuple), 9); http_hash4 = qvod2http(std::get<4>(qvod_hash_tuple), 1); break; case 0x00000200: case 0x00000600: case 0x00000A00: case 0x00000E00: http_hash1 = qvod2http(std::get<1>(qvod_hash_tuple), 9); http_hash2 = qvod2http(std::get<2>(qvod_hash_tuple), 7); http_hash3 = qvod2http(std::get<3>(qvod_hash_tuple), 1); http_hash4 = qvod2http(std::get<4>(qvod_hash_tuple), 9); break; default: http_hash1 = qvod2http(std::get<1>(qvod_hash_tuple), 9); http_hash2 = qvod2http(std::get<2>(qvod_hash_tuple), 7); http_hash3 = qvod2http(std::get<3>(qvod_hash_tuple), 8); http_hash4 = qvod2http(std::get<4>(qvod_hash_tuple), 1); break; } return std::make_tuple(http_hash0, http_hash1, http_hash2, http_hash3, http_hash4); }
void print_hash_tuple(hash_tuple_t hash_tuple) { std::cout << std::hex << std::setfill('0') << std::uppercase << std::setw(8) << std::get<0>(hash_tuple) << std::setw(8) << std::get<1>(hash_tuple) << std::setw(8) << std::get<2>(hash_tuple) << std::setw(8) << std::get<3>(hash_tuple) << std::setw(8) << std::get<4>(hash_tuple); }
void unit_test() { std::vector<hash_tuple_t> http_hash_tuple_vector = { std::make_tuple(0x2695D1A5, 0x443E4066, 0x3A846960, 0xA759C413, 0xA047D585), std::make_tuple(0xB138491B, 0x7ECBAF71, 0xEDEF1531, 0xC3F097B4, 0x3FF3F3A5), std::make_tuple(0x65A8A5E4, 0x0DCFE188, 0x86183574, 0xFC37CA8D, 0x033012EF), std::make_tuple(0xBEEDB7ED, 0x9D0BE6C6, 0x5C06941C, 0xADE919C7, 0xC5F242B7), std::make_tuple(0xC4021657, 0x5C5C7EBD, 0xC8A29063, 0xFB8E01DF, 0xFCFEFBE5), std::make_tuple(0xC5AA0BD7, 0x8873FF74, 0xBC3A1FE9, 0x133DF653, 0xAF82D3B5), std::make_tuple(0xCA9058A7, 0x4D98EA64, 0x584201C5, 0x3DE1C250, 0x7DEE46FA), std::make_tuple(0x7584CAB2, 0xEB4A84DA, 0x8C308165, 0x48179FC2, 0xE4A244E9), std::make_tuple(0x900EEA13, 0x690FAD33, 0xC1F14F24, 0xA8438FBD, 0x0B911D87), std::make_tuple(0x1B01188C, 0x744BF060, 0x4C47C81C, 0xFD089C56, 0x6CCDED2D), std::make_tuple(0xC0580F22, 0x2C876931, 0xBE5B2FE2, 0x83FFC574, 0xAE52C3E1), std::make_tuple(0xFFBDFE95, 0xDC086201, 0xC75FBA99, 0x7B58FDAB, 0x753D3E96), std::make_tuple(0xC8594D03, 0x757C7DB2, 0xC56F30DA, 0x09886D0C, 0xCE0B5457), std::make_tuple(0x433594F1, 0x5727054F, 0x0D2C67B7, 0x54250B38, 0xA42CB5CF), std::make_tuple(0xF8DA04C2, 0x66BAE2C0, 0xCADB48CC, 0x08D1F558, 0xB3DBCF79), std::make_tuple(0xBB5E3BEE, 0xA36A6A56, 0xDEB9EFCA, 0xCF506CBE, 0xFFABE491) };
for(const auto& http_hash_tuple : http_hash_tuple_vector) { auto qvod_hash_tuple = http_hash_to_qvod_hash(http_hash_tuple); auto http_hash_tuple_cvt = qvod_hash_to_http_hash(qvod_hash_tuple); assert(http_hash_tuple == http_hash_tuple_cvt); } }
int main() { std::string http_hash_string = "3BA3B4EA759CA9043F887B1B29985677DB38AD03"; assert(http_hash_string.size() == 40); std::uint32_t http_hash0 = std::stoul(http_hash_string.substr(0, 8), 0, 16); std::uint32_t http_hash1 = std::stoul(http_hash_string.substr(8, 8), 0, 16); std::uint32_t http_hash2 = std::stoul(http_hash_string.substr(16, 8), 0, 16); std::uint32_t http_hash3 = std::stoul(http_hash_string.substr(24, 8), 0, 16); std::uint32_t http_hash4 = std::stoul(http_hash_string.substr(32, 8), 0, 16); hash_tuple_t http_hash_tuple = std::make_tuple(http_hash0, http_hash1, http_hash2, http_hash3, http_hash4); auto qvod_hash_tuple = http_hash_to_qvod_hash(http_hash_tuple); print_hash_tuple(qvod_hash_tuple); std::cout << std::endl; }
|