Module: Base85::Rfc1924

Extended by:
ModuleMethods
Defined in:
lib/base85/rfc1924.rb

Overview

RFC 1924 base85 encoding

Author:

  • sd77

Constant Summary collapse

ALPHABET =

RFC1924 alphabet

"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"

Constants included from ModuleMethods

ModuleMethods::LUT

Class Method Summary collapse

Methods included from ModuleMethods

decode, encode, encode_word

Class Method Details

.decode_char(char) ⇒ Integer

Decode a character from RFC 1924 alphabet and give its index in alphabet

Parameters:

  • char (String)

    a acharacter from base85 alphabet

Returns:

  • (Integer)

    index of this character in alphabet

Raises:

  • DecodeError char is not known in alphabet



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/base85/rfc1924.rb', line 23

def self.decode_char(char)
  case char
  when "0".."9"
    char.ord - 48
  when "A".."Z"
    char.ord - 55 # - 65 + 10
  when "a".."z"
    char.ord - 61 # - 97 + 36
  when "!", "#".."&", "(".."+", "-", ";".."@", "^".."`", "{".."~"
    ALPHABET.index(char)
  else
    raise DecodeError, "unknown character '#{char}'"
  end
end

.encode_value(value) ⇒ String

Encode a value (0..84 integer) to a RFC 1924 character

Parameters:

  • value (Integer)

Returns:

  • (String)


15
16
17
# File 'lib/base85/rfc1924.rb', line 15

def self.encode_value(value)
  ALPHABET[value]
end