Skip to content

Instantly share code, notes, and snippets.

@m1el

m1el/base256.js

Last active Dec 18, 2020
Embed
What would you like to do?
// http://hewo.xedoloh.com/2015/04/base-256/
const BASE_START = "bghjklnpqrstvwyz";
const BASE_MID = "aeio";
const BASE_END = "cdfm";
const b256_encode = (source) => {
let buffer = '';
for (let byte of source) {
buffer += BASE_START[(byte >> 4)];
buffer += BASE_MID[((byte >> 2) & 0b11)];
buffer += BASE_END[(byte & 0b11)];
}
return buffer;
}
// http://hewo.xedoloh.com/2015/04/base-256/
const BASE_START: &[u8] = b"bghjklnpqrstvwyz";
const BASE_MID: &[u8] = b"aeio";
const BASE_END: &[u8] = b"cdfm";
fn b256_encode(source: &[u8]) -> String {
let mut buffer = String::with_capacity(source.len() * 3);
for &byte in source {
buffer.push(BASE_START[(byte >> 4) as usize] as char);
buffer.push(BASE_MID[((byte >> 2) & 0b11) as usize] as char);
buffer.push(BASE_END[(byte & 0b11) as usize] as char);
}
buffer
}
fn main() {
println!("{}", b256_encode(b"\x00\x01"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment