Skip to content

Commit

Permalink
edge
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Aug 21, 2024
1 parent 4a64ed4 commit 1dc0717
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"ExpandedNodes": [
""
],
"SelectedNode": "\\Untitled 3.jpg",
"PreviewInSolutionExplorer": false
}
26 changes: 9 additions & 17 deletions New folder/include/base58.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <memory>


static const int8_t b58digits_map[128] = {
Expand All @@ -24,7 +25,7 @@ inline bool b58tobin(void *bin /* out */ , size_t *binszp /* in - out */ , const
const unsigned char *b58u = (const unsigned char *)b58;
unsigned char *binu = (unsigned char *)bin;
size_t outsz = (binsz + 3) / 4;
uint32_t *out = new uint32_t[outsz]();
std::shared_ptr<uint32_t[]> out(new uint32_t[outsz]());
uint64_t t;
uint32_t c;
size_t i, j;
Expand All @@ -43,15 +44,11 @@ inline bool b58tobin(void *bin /* out */ , size_t *binszp /* in - out */ , const
{
if (b58u[i] & 0x80)
{
delete[] out;

// High-bit set on invalid digit
return false;
}
if (b58digits_map[b58u[i]] == -1)
{
delete[] out;

// Invalid base58 digit
return false;
}
Expand All @@ -64,15 +61,12 @@ inline bool b58tobin(void *bin /* out */ , size_t *binszp /* in - out */ , const
}
if (c)
{
delete[] out;

// Output number too big (carry to the next int32)
return false;
}
if (out[0] & zeromask)
{
// Output number too big (last int32 filled too far)
delete[] out;
return false;
}
}
Expand All @@ -81,13 +75,13 @@ inline bool b58tobin(void *bin /* out */ , size_t *binszp /* in - out */ , const
switch (bytesleft)
{
case 3:
*(binu++) = *((uint8_t*)out + 2);
*(binu++) = *((uint8_t*)&out[0] + 2);
/* Fall Through */
case 2:
*(binu++) = *((uint8_t*)out + 1);
*(binu++) = *((uint8_t*)&out[0] + 1);
/* Fall Through */
case 1:
*(binu++) = *(uint8_t*)out;
*(binu++) = *(uint8_t*)&out[0];
j++;
break;
default:
Expand All @@ -96,11 +90,10 @@ inline bool b58tobin(void *bin /* out */ , size_t *binszp /* in - out */ , const

for (; j < outsz; j++)
{
std::reverse((char *)(out + j), (char *)(out + j) + 4);
std::reverse((char *)(&out[0] + j), (char *)(&out[0] + j) + 4);
*(uint32_t *)binu = out[j];
binu = binu + 4;
}
delete[] out;
//size of the result binary,modified that way that the number of leading zeroes in it replaced by the count of leading '1' symbols in given string.
binu = (unsigned char *)bin;
for (i = 0; i < binsz; i++)
Expand All @@ -114,6 +107,7 @@ inline bool b58tobin(void *bin /* out */ , size_t *binszp /* in - out */ , const
return true;
}


static const char b58digits_ordered[59] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

inline bool b58enc(char* b58 /* out */ , size_t *b58sz /* in - out */ , const void *data /* in */ , size_t binsz /* in */ )
Expand All @@ -124,8 +118,7 @@ inline bool b58enc(char* b58 /* out */ , size_t *b58sz /* in - out */ , const v
while (zcount < binsz && !bin[zcount])
zcount++;
const unsigned int size = (binsz - zcount) * 138 / 100 + 1; //latter is a smth like a logarithm of 256 to base 58 , but not exactly.
unsigned char *buf = new unsigned char[size]();

std::shared_ptr<unsigned char[]> buf(new unsigned char[size]());
high = size - 1;
for (i = zcount; i < binsz; i++)
{
Expand All @@ -144,7 +137,6 @@ inline bool b58enc(char* b58 /* out */ , size_t *b58sz /* in - out */ , const v
if (*b58sz < zcount + size - j + 1)
{
*b58sz = zcount + size - j + 1;
delete[] buf;
return false;
}

Expand All @@ -154,12 +146,12 @@ inline bool b58enc(char* b58 /* out */ , size_t *b58sz /* in - out */ , const v
for (i = zcount; j < size; i++, j++)
b58[i] = b58digits_ordered[buf[j]];

delete[] buf;
b58[i] = '\0';
*b58sz = i + 1;
return true;
}


inline std::pair<int, std::string> b58decode(const std::string &b58) {
if (b58.size() > LONG_MAX >> 4) return std::pair<int, std::string> (-7, std::string());
size_t decodedSize = b58.size() << 3;;
Expand Down
Binary file modified out/build/x64-Release/CMakeProject1/compressor.exe
Binary file not shown.
Binary file modified out/build/x64-Release/CMakeProject1/decompressor.exe
Binary file not shown.
Binary file modified tool3_2048/.vs/tool3/v16/.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions tool3_2048/tool3/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ std::shared_ptr<BYTE[]> b(new BYTE[lkm]);

std::ifstream cd;
cd.open(L"f.raw", std::ios_base::binary);
cd.read(&b[0], lkm);
cd.read((char *)&b[0], lkm);

WAVEHDR haze = {&b[0] , lkm };
WAVEHDR haze = {(char *)&b[0] , lkm };
waveOutPrepareHeader(hWaveOut, &haze, sizeof(WAVEHDR));
waveOutWrite(hWaveOut, &haze, sizeof(WAVEHDR));

Expand Down

0 comments on commit 1dc0717

Please sign in to comment.