move to new cspot

This commit is contained in:
philippe44
2023-03-25 16:48:41 -07:00
parent c712b78931
commit 008c36facf
2983 changed files with 465270 additions and 13569 deletions

View File

@@ -23,7 +23,20 @@ uint64_t hton64(uint64_t value) {
}
}
std::string bytesToHexString(std::vector<uint8_t>& v) {
std::vector<uint8_t> stringHexToBytes(const std::string & s) {
std::vector<uint8_t> v;
v.reserve(s.length() / 2);
for (std::string::size_type i = 0; i < s.length(); i += 2) {
std::string byteString = s.substr(i, 2);
uint8_t byte = (uint8_t) strtol(byteString.c_str(), NULL, 16);
v.push_back(byte);
}
return v;
}
std::string bytesToHexString(const std::vector<uint8_t>& v) {
std::stringstream ss;
ss << std::hex << std::setfill('0');
std::vector<uint8_t>::const_iterator it;
@@ -64,6 +77,28 @@ std::vector<uint8_t> bigNumAdd(std::vector<uint8_t> num, int n)
return num;
}
std::vector<uint8_t> bigNumDivide(std::vector<uint8_t> num, int n)
{
auto carry = 0;
for (int x = 0; x < num.size(); x++)
{
int res = num[x] + carry * 256;
if (res < n)
{
carry = res;
num[x] = 0;
}
else
{
// Carry the rest of the division
carry = res % n;
num[x] = res / n;
}
}
return num;
}
std::vector<uint8_t> bigNumMultiply(std::vector<uint8_t> num, int n)
{
auto carry = 0;