Skip to content

Instantly share code, notes, and snippets.

@spencertipping
Created June 8, 2011 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spencertipping/1014640 to your computer and use it in GitHub Desktop.
Save spencertipping/1014640 to your computer and use it in GitHub Desktop.
Caterwaul implementation of base-85 encoding
it.encode85(s) = encoded -where [encode_block(n) = n[5] *[String.fromCharCode(33 + n / powers_of_85[4 - x] % 85)] -seq -re- it.join(''),
padded = s.length & 1 ? s + String.fromCharCode(0) : s,
encoded_string = n[0, padded.length, 2] *[encode_block((padded.charCodeAt(x) << 16) >>> 0 | padded.charCodeAt(x + 1))] -seq -re- it.join(''),
encoded = s.length & 1 ? encoded_string.substr(0, encoded_string.length - 2) : encoded_string],
it.decode85(s) = decoded -where [decode_block(n) = String.fromCharCode(n >>> 16) + String.fromCharCode(n >>> 0 & 0xffff),
block_value(s) = n[6] /[x * 85 + s.charCodeAt(x0 - 1) - 33] -seq,
padded = s.length % 5 ? '#{s}uu' : s,
decoded_string = n[0, padded.length, 5] *[decode_block(block_value(padded.substr(x, 5)))] -seq -re- it.join(''),
decoded = s.length % 5 ? decoded_string.substr(0, decoded_string.length - 1) : decoded_string],
where [powers_of_85 = n[5] *~[n[1, x + 2] /[x * 85]] -seq]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment