A way to encode binary data in an ASCII string.
Let's try to encrypt a piece text, for example "Hello World!"
Now, we'll take it's ASCII representation:
72 101 108 108 111 10 119 111 114 108 100 33
We'll convert that to binary:
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100 00100001
After that, we'll split this 8 bit stream to a 6 bit stream:
010010 000110 010101 101100 011011 000110 111100 100000 010101 110110 111101 110010 011011 000110 010000 100001
If your string cannot split up in a 6 bit stream, add padding '0' at the end, we'll replace them by '='
Now, we'll convert this 6 bit stream to numbers in base 10:
18 6 21 44 27 6 60 32 21 54 61 50 27 6 16 33
And using the Base64 table:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
We have:
SGVsbG8gV29ybGQh
Using the output from the encryption, we have:
SGVsbG8gV29ybGQh
We'll start by decompose it to numbers using the Base64 table:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
so we have:
18 6 21 44 27 6 60 32 21 54 61 50 27 6 16 33
We'll convert this into a 6 bit stream:
010010 000110 010101 101100 011011 000110 111100 100000 010101 110110 111101 110010 011011 000110 010000 100001
Now, we'll take this 6 bit stream, and we'll turn it to a 8 bit stream:
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100 00100001
Using this 8 bit stream, we'll convert it to decimal numbers:
72 101 108 108 111 10 119 111 114 108 100 33
And we'll use ASCII to convert these numbers to characters:
Hello World!
Language | Encrypt | Decrypt |
---|---|---|
Javascript | encrypt.js | decrypt.js |
PHP | encrypt.php | decrypt.php |
Python | encrypt.py | decrypt.py |
Swift | lib.swift | lib.swift |
NPM:
npm i @cryptoolsorg/base64
Tests are automatically handled by Travis CI.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
Made with ❤️ at CrypTools.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the
file for details