Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can use this library for my program? #3

Open
ungaro59 opened this issue Jan 3, 2018 · 0 comments
Open

How can use this library for my program? #3

ungaro59 opened this issue Jan 3, 2018 · 0 comments

Comments

@ungaro59
Copy link

ungaro59 commented Jan 3, 2018

Hello,

I want to use your library in my harbour program to transform big number like this :
0x00119B098E2E980A229E139A9ED01A469E518E6F2690AFE11C
in base 58 like this :
12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX

But actually i must use a very long program (see under) to convert big number to base 58.
But with your Tbignumber class, i will reduce my program.
Like : BigNumber%58 (very simple)
example : https://stackoverflow.com/questions/8970715/how-do-i-base58-encode-a-string

I not understand how to implement your class in my program.
How can use your library to reduce my program ?
How can compile with harbour to add your class? (i use harbour core V3 in Windows environnement https://github.com/harbour/core)

Thank you in advance.

?To_base58("00119B098E2E980A229E139A9ED01A469E518E6F2690AFE11C")

function To_base58(Chaine2)
LOCAL i,j, ALPHABET
Local chaine2, Chaine4
Local sZero, binsz, nsize, buf, buf58, high,Carry, zcount

//Transform Ascii to hex
Chaine4=""
for i=1 to len(chaine2)/2
       chaine4+=chr(HB_HexToNum(substr(chaine2,(i-1)*2+1,2)))
next

ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
// Count leading zeros. 
zcount=1
DO WHILE zcount < len(Chaine4) .and. substr(Chaine4,zcount,1) = Chr(0)
   zcount++
ENDDO
   
binsz = len(chaine4)

nsize = int((binsz-zcount)*138/100 + 3)
buf = replicate(chr(0),nsize) 

high = nsize
FOR i = zcount TO binsz
    j = nsize
    Carry = Asc(substr(Chaine4,i,1))
    Do while j>0
    	Carry = Carry + 256*Asc(substr(buf,j,1))
	buf = stuff(buf,j,1,chr(mod(Carry,58)))
	Carry = int(Carry / 58)
	j--
	if Carry = 0 .and. j<high
	   exit
	endif
    Enddo
	
    high = j
NEXT
  
buf58=""  
zcount--
if zcount>0
   for i=1 to zcount
       buf58+="1"
   next
endif

zcount=1
Do while Asc(substr(buf,zcount,1))=0
   zcount++	
Enddo     
for j=zcount to nsize
  buf58+=substr(ALPHABET,Asc(substr(buf,j,1))+1,1)
next
return buf58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant