MCPcopy Create free account
hub / github.com/albertobsd/keyhunt / GetBaseN

Method GetBaseN

secp256k1/Int.cpp:1017–1053  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1015// ------------------------------------------------
1016
1017char* Int::GetBaseN(int n,const char *charset) {
1018 char *ret = (char*) calloc(1,1024);
1019
1020 Int N(this);
1021 int offset = 0;
1022 int isNegative = N.IsNegative();
1023 if (isNegative) N.Neg();
1024
1025 // TODO: compute max digit
1026 unsigned char digits[1024];
1027 memset(digits, 0, sizeof(digits));
1028
1029 int digitslen = 1;
1030 for (int i = 0; i < NB64BLOCK * 8; i++) {
1031 unsigned int carry = N.GetByte(NB64BLOCK*8 - i - 1);
1032 for (int j = 0; j < digitslen; j++) {
1033 carry += (unsigned int)(digits[j]) << 8;
1034 digits[j] = (unsigned char)(carry % n);
1035 carry /= n;
1036 }
1037 while (carry > 0) {
1038 digits[digitslen++] = (unsigned char)(carry % n);
1039 carry /= n;
1040 }
1041 }
1042
1043 // reverse
1044 if (isNegative)
1045 ret[offset++] = '-';
1046
1047 for (int i = 0; i < digitslen; i++)
1048 ret[offset++] = charset[digits[digitslen - 1 - i]];
1049
1050 if (offset == 0)
1051 ret[offset] = '0';
1052 return ret;
1053}
1054
1055// ------------------------------------------------
1056

Callers

nothing calls this directly

Calls 3

IsNegativeMethod · 0.45
NegMethod · 0.45
GetByteMethod · 0.45

Tested by

no test coverage detected