-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase58.cpp
48 lines (44 loc) · 1.46 KB
/
base58.cpp
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
#include <iostream>
#include <vector>
#include "base58.h"
namespace base58
{
namespace
{
const char * s("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
}
int findSymbol( const char c )
{
for ( int i=0; i< 58; i++ )
{
if ( s[i] == c )
return i;
}
return -1;
}
void write( const int index, std::ostream & out )
{
if ( index < 0 || index > 57 )
throw "base58: error in making output string";
out << s[ index ];
}
void read( std::istream & ist, std::vector< int > & out )
{
while ( ! ist.eof() )
{
char buff[1024];
ist.read( buff, 1024 );
int imax = ist.gcount();
for ( int i=0; i<imax; i++ )
{
if ( buff[ i ] == '\n' )
return;
int tmp = findSymbol( buff[ i ] );
if ( tmp != -1 )
out.push_back( tmp );
else
throw "base58: incorrect symbol found";
}
}
}
}