Last active
December 18, 2020 04:49
-
-
Save m1el/c25ab05a02c0fa60b6e695f920e33627 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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