Skip to content

NfNitLoop/mojibake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Mojibake

mojibake is a script to "mojibake"-ify binary data so that it can be copy/pasted between (unicode-aware) terminals

Introduction

The base64 format was designed to encode binary data within a set of characters that were safe for (text-only) e-mail. It was designed to be reasonably efficient -- each 8-bit base64 character can represent 6 bits of binary data. Or, 4 base64 characters represent 3 bytes of binary data.

Instead of optimizing for an efficient size transformations, what if you optimize for how many bytes you can represent in each character? Unicode has over 2^16 assigned characters, so you could represent two bytes per character!

It's not very space efficient, though. Those two bytes of binary data need 4-5 UTF-8 bytes to encode them as a unicode character.

But it looks cool!

Sample Use

Like Base64

$ date | base64
U3VuIE5vdiAgMiAxNjozNToxNCBHTVQgMjAxNAo=

$ date | mojibake 
๐ฅต๐ฆธ ๐คนฏ๐ง˜ ๐ข€ฒ๐ข€ฑ๐ฃ˜บ๐ฃŒต๐ฃจฑ๐ฃœ ๐ค๐ฅ ๐ฃˆฐ๐ฃ„ด๋ฆ

Look at all the characters you saved! :p

$ echo ๐ฅต๐ฆธ ๐คนฏ๐ง˜ ๐ข€ฒ๐ข€ฑ๐ฃ˜บ๐ฃŒต๐ฃจฑ๐ฃœ ๐ค๐ฅ ๐ฃˆฐ๐ฃ„ด๋ฆ | ./mojibake --decode
Sun Nov  2 16:35:17 GMT 2014

Like tar | base64

When I'm ssh-hopping around on machines, sometimes I just want to copy-paste a couple small script files somewhere. Sometimes I use tar cz foo bar | base64 to grab them. But it's even easier with mojibake:

$ mojibake foo bar 
๐ฅ‹๐ Œ„๐ก€๐  €๐  €้šญ๐ฆ‰…๐ €€๐ €€๐ €€๐ €€๐ ธ€๐ €€๐ Œ€๐กฐ€๐ฆ™ฏ๐ฆฝ•๐ฅ‰๐ €ƒ๐ค‰ž๐ฅ™”๐จž๐ฅ™”๐ง•ธ๐ ฌ€๐ „„้ฐช๐ €€๐ ”๐ €€๐ ƒณ๐คฃ็ƒฒ็นบ๐ขฃ๐ขฟŠ๐คฅ‘่ฌซ๐ ๐คฌ‡
๐  ˜ไนพ๐งฌ๐ €€๐ €Ž๐ €€๐ ๐คฌƒ๐ ”๐ €ˆ๐ €ˆ๐ €‰๐จ•ข๐ค”€๐ €€๐ €€๐ €€๐ “๐ €€๐ €ƒ๐ €œ๐ ข๐ฆ…ฒ๐ฅ•”๐ ค€๐ ฒ๐ฅน–๐ฅ’€๐ฅน–๐ฅ‘ต๐ง ‹๐ €๐ “ต๐ „€๐ €„๐ก€๐ €€๐ข—Šๅ ถ๐จ€ฐ
๐ ฐ„ๆŸ‡๐ขฅพ๐ ‰—๐ขฑ๐ค…๐ ˆ†๐กณ™๐ฅˆ’๐ชŒธ๐ขฃซ๐กމ้ถ๐จœŠๅ˜๐ Œฉ๐ฉฌ„๐จ™Š๐ค–Ÿไธ‡๐คˆŠ๐ฅ˜ๆžง๐ฅชป๐คนพ๐ค ๐จฆˆๅ ค๐ขŽ„๐ ตœ๐งƒฒ๐ ทฎ๐ง™็ ›๐ …๐คฌ‡๐ ขฃ๐ฅค€้ด๐ €€
๐ “๐ €€๐ ๐คฌ๐ ˆž๐ Œ”๐ €ˆ๐ €ˆ๐ ƒฏ๐จ‘ข๐ค”˜ไนพ๐งฌ๐ €€๐ €Ž๐ €€๐ €ƒ๐ €˜๐ €€๐ €€๐ €๐ €€๐ ‚ค๐จ„€๐ €€๐ ฆ๐ฆฝฏ๐ฅ•”๐ ”€๐ ‚๐ฅน–๐ฅ‘ต๐ง ‹๐ €๐ “ต๐ „€๐ €„๐ก€๐ €€๐ฅ‹
๐ „‚๐กธƒ๐ก€๐  €๐  €๐ ฆ…๐ฆ‰…๐ช™๐ ƒฐ๐คฌ€๐ €€๐ฅŒ€๐ €€๐ Œ€๐ก €๐ €€๐ €€๐ „€๐ €€๐ช’๐ฅด€๐ €€๐ฆ‰ก๐ง‰•๐ฅ…๐ €ƒ๐ง‰ž๐ฅ™”๐ง•ธ๐ ฌ€๐ „„้ฐช๐ €€๐ ”๐ €€๐ ๐คฌ…๐ ˜€๐ €€๐ €‚
๐ €‚๐ ‚’๐ €€๐ ƒต๐ €€๐ €€๋œ

Then, on my destination machine:

$ mojibake --unzip 
Paste the mojibaked zip file. Type '.' to finish.
๐ฅ‹๐ Œ„๐ก€๐  €๐  €้šญ๐ฆ‰…๐ €€๐ €€๐ €€๐ €€๐ ธ€๐ €€๐ Œ€๐กฐ€๐ฆ™ฏ๐ฆฝ•๐ฅ‰๐ €ƒ๐ค‰ž๐ฅ™”๐จž๐ฅ™”๐ง•ธ๐ ฌ€๐ „„้ฐช๐ €€๐ ”๐ €€๐ ƒณ๐คฃ็ƒฒ็นบ๐ขฃ๐ขฟŠ๐คฅ‘่ฌซ๐ ๐คฌ‡
๐  ˜ไนพ๐งฌ๐ €€๐ €Ž๐ €€๐ ๐คฌƒ๐ ”๐ €ˆ๐ €ˆ๐ €‰๐จ•ข๐ค”€๐ €€๐ €€๐ €€๐ “๐ €€๐ €ƒ๐ €œ๐ ข๐ฆ…ฒ๐ฅ•”๐ ค€๐ ฒ๐ฅน–๐ฅ’€๐ฅน–๐ฅ‘ต๐ง ‹๐ €๐ “ต๐ „€๐ €„๐ก€๐ €€๐ข—Šๅ ถ๐จ€ฐ
๐ ฐ„ๆŸ‡๐ขฅพ๐ ‰—๐ขฑ๐ค…๐ ˆ†๐กณ™๐ฅˆ’๐ชŒธ๐ขฃซ๐กމ้ถ๐จœŠๅ˜๐ Œฉ๐ฉฌ„๐จ™Š๐ค–Ÿไธ‡๐คˆŠ๐ฅ˜ๆžง๐ฅชป๐คนพ๐ค ๐จฆˆๅ ค๐ขŽ„๐ ตœ๐งƒฒ๐ ทฎ๐ง™็ ›๐ …๐คฌ‡๐ ขฃ๐ฅค€้ด๐ €€
๐ “๐ €€๐ ๐คฌ๐ ˆž๐ Œ”๐ €ˆ๐ €ˆ๐ ƒฏ๐จ‘ข๐ค”˜ไนพ๐งฌ๐ €€๐ €Ž๐ €€๐ €ƒ๐ €˜๐ €€๐ €€๐ €๐ €€๐ ‚ค๐จ„€๐ €€๐ ฆ๐ฆฝฏ๐ฅ•”๐ ”€๐ ‚๐ฅน–๐ฅ‘ต๐ง ‹๐ €๐ “ต๐ „€๐ €„๐ก€๐ €€๐ฅ‹
๐ „‚๐กธƒ๐ก€๐  €๐  €๐ ฆ…๐ฆ‰…๐ช™๐ ƒฐ๐คฌ€๐ €€๐ฅŒ€๐ €€๐ Œ€๐ก €๐ €€๐ €€๐ „€๐ €€๐ช’๐ฅด€๐ €€๐ฆ‰ก๐ง‰•๐ฅ…๐ €ƒ๐ง‰ž๐ฅ™”๐ง•ธ๐ ฌ€๐ „„้ฐช๐ €€๐ ”๐ €€๐ ๐คฌ…๐ ˜€๐ €€๐ €‚
๐ €‚๐ ‚’๐ €€๐ ƒต๐ €€๐ €€๋œ
.Archive:  /var/folders/h6/y72jsht13xx_0sgnrnb3m68c0000gn/T/tmp7yidcl5k.zip
  inflating: foo                     
  inflating: bar                     

Tips

Fonts

If you want to see the cool chinese characters instead of a screen full of boxes, you'll need to install fonts that support the unicode CJK Unified Ideographs Extension B. You may already have a font that can handle these characters. If not, I recommend the freely available Hanazono.

About

A silly script to convert binary data to unicode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages