func (e *Encoding) Encode(maxLen int) string {
	source, err := memguard.NewImmutableRandom(maxLen)
	if err != nil {
		fmt.Println(err)
		memguard.SafeExit(2)
	}

	defer source.Destroy()

	if source.Size() == 0 {
		return ""
	}

	digits := []int{0}

	for i := 0; i < source.Size(); i++ {
		carry := int(source.Buffer()[i])

		for j := 0; j < len(digits); j++ {
			carry += digits[j] << 8
			digits[j] = carry % e.base
			carry = carry / e.base
		}

		for carry > 0 {
			digits = append(digits, carry%e.base)
			carry = carry / e.base
		}
	}

	var res bytes.Buffer

	for k := 0; source.Buffer()[k] == 0 && k < source.Size()-1; k++ {
		res.WriteRune(e.alphabet[0])
	}

	for q := len(digits) - 1; q >= 0; q-- {
		res.WriteRune(e.alphabet[digits[q]])
	}

	result := res.String()

	return result[0:maxLen]
}
// Encode function receives a byte slice and encodes it to a string using the alphabet provided
Encode function receives a byte slice and encodes it to a string using the alphabet provided
// Encode function receives a byte slice and encodes it to a string using the alphabet provided
func (e *Encoding) Encode(maxLen int) string {
	source, err := memguard.NewImmutableRandom(maxLen)
	if err != nil {
		fmt.Println(err)
		memguard.SafeExit(2)
	}
	defer source.Destroy()
	if source.Size() == 0 {
		return ""
	}
	digits := []int{0}
	for i := 0; i < source.Size(); i++ {
		carry := int(source.Buffer()[i])
		for j := 0; j < len(digits); j++ {
			carry += digits[j] << 8
			digits[j] = carry % e.base
			carry = carry / e.base
		}
		for carry > 0 {
			digits = append(digits, carry%e.base)
			carry = carry / e.base
		}
	}
	var res bytes.Buffer
	for k := 0; source.Buffer()[k] == 0 && k < source.Size()-1; k++ {
		res.WriteRune(e.alphabet[0])
	}
	for q := len(digits) - 1; q >= 0; q-- {
		res.WriteRune(e.alphabet[digits[q]])
	}
	result := res.String()
	return result[0:maxLen]
}
func ( e * Encoding ) Encode ( maxLen int ) string { source , err := memguard . NewImmutableRandom ( maxLen ) if err != nil { fmt . Println ( err ) memguard . SafeExit ( 2 ) } defer source . Destroy ( ) if source . Size ( ) == 0 { return " " } digits := [ ] int { 0 } for i := 0 ; i < source . Size ( ) ; i ++ { carry := int ( source . Buffer ( ) [ i ] ) for j := 0 ; j < len ( digits ) ; j ++ { carry += digits [ j ] << 8 digits [ j ] = carry % e . base carry = carry / e . base } for carry > 0 { digits = append ( digits , carry % e . base ) carry = carry / e . base } } var res bytes . Buffer for k := 0 ; source . Buffer ( ) [ k ] == 0 && k < source . Size ( ) - 1 ; k ++ { res . WriteRune ( e . alphabet [ 0 ] ) } for q := len ( digits ) - 1 ; q >= 0 ; q -- { res . WriteRune ( e . alphabet [ digits [ q ] ] ) } result := res . String ( ) return result [ 0 : maxLen ] }
Encode function receives a byte slice and encodes it to a string using the alphabet provided
Encode function receives a byte slice and encodes it to a string using the alphabet provided