Skip to content

Encoding/decoding with custom character sets #12

Description

@calh

Hello,

This is probably a dumb/simple question, but I can't figure out how to decode a string with a custom character set. Here's a quick example:

1.9.3-p545 :001 > BASE62_ALPHABET = (0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] 
1.9.3-p545 :002 > 809145531659995.b(62).to_s(BASE62_ALPHABET[0,62])
 => "3HLszsQsP" 
1.9.3-p545 :003 > "3HLszsQsP".b(BASE62_ALPHABET[0,62])
NoMethodError: undefined method `<' for #<Array:0x00000006559a78>
1.9.3-p545 :008 > "3HLszsQsP".b(62).to_i
 => 716130955509941 

What am I doing wrong here?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions