bytesmap

package
v0.0.0-...-6484783 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2017 License: MIT, MIT Imports: 1 Imported by: 0

README ΒΆ

Bytesmap emoji encoding GoDoc

The package bytesmap can be used to encode strings into emojis. Can be used to "humanize" hard to remember/recognize texts such as Hashes, keys, other encodes like base64, ip's and so on.

Depending on the text the result may have fewer characters, but definately will have more bytes in length, so is not an efficient compresison method, is just an encoding like base64, but way cooler and friendlier.

Demo

We have built a full working demo at emoji-compress.com β€Ό

How

The algorithm is very simple: it split the string in a series of bytes, and map each byte by its value to an unique emoji. A byte can have only 255 possible values, so we only need 255 different emojis to encode ... anything.

Source

The package is a Go port of @ayende 's emoji encoder. He also uses it to encode the Licenses for his product when they are sent to the customers.

There are other advantages. This data is actually a 256 bits key for use in encryption. And you can actually show it to a user and have a reasonably good chance that they will be able to tell it apart from something else. It rely on the ability of humans to recognize shapes, but it will be very hard for them to actually tell someone your key.

Example

	ugly := []string{
		"127.0.0.1",
		"ZW1vamk=", //base64 for "emoji"
		"5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", //sha1 for "password"
	}

	for _, s := range ugly {
		emojified, err := EncodeString(s)
		if err != nil {
			log.Panic(err)
		}
		fmt.Printf("%s => %s\n", s, emojified)
	}
	// Output: 127.0.0.1 => πŸ™‡πŸ™ˆπŸ™πŸ™€πŸ™†πŸ™€πŸ™†πŸ™€πŸ™‡
	//ZW1vamk= => πŸš‡πŸšƒπŸ™‡πŸšΎπŸš•πŸš¬πŸšͺβœ‰
	//5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 => πŸ™‹πŸš—πŸš•πŸš•πŸ™ŒπŸ™‡πŸš’πŸ™ŠπŸš™πŸ™πŸš—πŸ™πŸ™‰πŸš€πŸ™‰πŸš€πŸ™†πŸ™ŒπŸ™ŽπŸ™ˆπŸ™ˆπŸ™‹πŸ™†πŸš—πŸ™ŒπŸš™πŸš€πŸ™ŽπŸ™‰πŸ™‰πŸ™‡πŸš—πŸ™πŸš’πŸš’πŸ™ŒπŸ™ŽπŸš€πŸššπŸ™Ž

This package has unit tests, GoDoc and Examples.

About

This package is part of a group of emoji-related encoding and compression algorithms built for fun and academic purposes in Go.

Copyright (c) 2017 B.G.Adrian & @Davidescus

Documentation ΒΆ

Overview ΒΆ

Package bytesmap can be used to encode strings into emojis. Can be useful to "humanize" hard to remember/recognize texts such as Hashes, keys, other encodes like base64, ip's and so on.

Depending on the text the result may have fewer characters, but definately will have more bytes in length, so is not an efficient compresison method, is just an encoding like base64, but way cooler and friendlier.

The algorithm is very simple: it split the string in a series of bytes, and map each byte by its value to an unique emoji. A byte can have only 255 possible values, so we only need 255 different emojis to encode ... anything.

Index ΒΆ

Examples ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Decode ΒΆ

func Decode(encoded []byte) (source []byte, err error)

Decode an emoji encoded to it's original form.

func DecodeString ΒΆ

func DecodeString(encoded string) (string, error)

DecodeString overload the Decode() function.

Example ΒΆ
beauty := []string{
	"πŸ™‡πŸ™ˆπŸ™πŸ™€πŸ™†πŸ™€πŸ™†πŸ™€πŸ™‡", //127.0.0.1
	"πŸš‡πŸšƒπŸ™‡πŸšΎπŸš•πŸš¬πŸšͺβœ‰",  //base64 for "emoji"
	"πŸ™‹πŸš—πŸš•πŸš•πŸ™ŒπŸ™‡πŸš’πŸ™ŠπŸš™πŸ™πŸš—πŸ™πŸ™‰πŸš€πŸ™‰πŸš€πŸ™†πŸ™ŒπŸ™ŽπŸ™ˆπŸ™ˆπŸ™‹πŸ™†πŸš—πŸ™ŒπŸš™πŸš€πŸ™ŽπŸ™‰πŸ™‰πŸ™‡πŸš—πŸ™πŸš’πŸš’πŸ™ŒπŸ™ŽπŸš€πŸššπŸ™Ž", //sha1 for "password"
}
for _, s := range beauty {
	original, err := DecodeString(s)
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("%s => %s\n", s, original)
}
Output:

πŸ™‡πŸ™ˆπŸ™πŸ™€πŸ™†πŸ™€πŸ™†πŸ™€πŸ™‡ => 127.0.0.1
πŸš‡πŸšƒπŸ™‡πŸšΎπŸš•πŸš¬πŸšͺβœ‰ => ZW1vamk=
πŸ™‹πŸš—πŸš•πŸš•πŸ™ŒπŸ™‡πŸš’πŸ™ŠπŸš™πŸ™πŸš—πŸ™πŸ™‰πŸš€πŸ™‰πŸš€πŸ™†πŸ™ŒπŸ™ŽπŸ™ˆπŸ™ˆπŸ™‹πŸ™†πŸš—πŸ™ŒπŸš™πŸš€πŸ™ŽπŸ™‰πŸ™‰πŸ™‡πŸš—πŸ™πŸš’πŸš’πŸ™ŒπŸ™ŽπŸš€πŸššπŸ™Ž => 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8

func Encode ΒΆ

func Encode(source []byte) (encoded []byte, err error)

Encode a stream of bytes (we presume it is a string) into an emoji form. Each possible byte value (0-255) is mapped to an unique emoji.

func EncodeString ΒΆ

func EncodeString(source string) (string, error)

EncodeString is an overload of Encode(), most of the cases you'll need this to avoid code duplication ([]byte <-> string).

Example ΒΆ
ugly := []string{
	"127.0.0.1",
	"ZW1vamk=", //base64 for "emoji"
	"5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", //sha1 for "password"
}

for _, s := range ugly {
	emojified, err := EncodeString(s)
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("%s => %s\n", s, emojified)
}
Output:

127.0.0.1 => πŸ™‡πŸ™ˆπŸ™πŸ™€πŸ™†πŸ™€πŸ™†πŸ™€πŸ™‡
ZW1vamk= => πŸš‡πŸšƒπŸ™‡πŸšΎπŸš•πŸš¬πŸšͺβœ‰
5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 => πŸ™‹πŸš—πŸš•πŸš•πŸ™ŒπŸ™‡πŸš’πŸ™ŠπŸš™πŸ™πŸš—πŸ™πŸ™‰πŸš€πŸ™‰πŸš€πŸ™†πŸ™ŒπŸ™ŽπŸ™ˆπŸ™ˆπŸ™‹πŸ™†πŸš—πŸ™ŒπŸš™πŸš€πŸ™ŽπŸ™‰πŸ™‰πŸ™‡πŸš—πŸ™πŸš’πŸš’πŸ™ŒπŸ™ŽπŸš€πŸššπŸ™Ž

Types ΒΆ

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL