I am trying to translate this code from Javascript to Go.
if(secret_binary % secret_alphabet_bitlength > 0) {
secret_binary += zeropad("0", secret_alphabet_bitlength - (secret_binary % secret_alphabet_bitlength));
}
secret_binary is a string
(representing a binary).
secret_alphabet_bitlength is an int
(6
to be precise).
Note : zeropad function is just adding the number of 0
needed. I replace it by the for
loop that you can see below.
From what I understood in this topic Remainder/Modulus of string is a number, the ToNumber
is applied to the value that is not a string.
Fine, that is what I tried.
bToBig, _ := new(big.Int).SetString(secretBinary, 2)
nb := int64(secretAlphabetBitLength) - (bToBig.Int64() % int64(secretAlphabetBitLength))
if bToBig.Int64()%int64(secretAlphabetBitLength) > 0 {
for i := 0; int64(i) < nb; i++ {
secretBinary += "0"
}
}
This 000001001100010000000001000111000001000000
is becoming 0000010011000100000000010001110000010000000000
for both the Javascript code and the Golang one. So it is "working", if I can say so.
But, this 001011001001000100001110000001010000010000000101000100000000000010011001000000010000001001010010000001010100000101010011000000
should become 0010110010010001000011100000010100000100000001010001000000000000100110010000000100000010010100100000010101000001010100110000000000
according to the Javascript code but here is what I get 00101100100100010000111000000101000001000000010100010000000000001001100100000001000000100101001000000101010000010101001100000000
(only two zeros are added instead of 4)
I do not know what to do, I tried to parse the string into INT, HEXA, BINARY, OCTAL, etc.. nothing work.