Skip to content

Instantly share code, notes, and snippets.

@sspreitzer
Last active May 13, 2021 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sspreitzer/cd686f47946dfc50fe978fffc69faca2 to your computer and use it in GitHub Desktop.
Save sspreitzer/cd686f47946dfc50fe978fffc69faca2 to your computer and use it in GitHub Desktop.
ruby base16
# Ruby base16 encode/decode
# (c) Sascha Spreitzer, 2016
# MIT license
def b16decode(what)
chars = ''
ret = ''
what.each_char do |c|
chars += c
if chars.size == 2
ret += chars.to_i(16).chr
chars = ''
end
end
ret
end
def b16encode(what)
ret = ''
what.each_char do |c|
ch = c.ord.to_s(16)
if ch.size == 1
ch = '0' + ch
end
ret += ch
end
ret.upcase
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment