2016-03-30 23:04:14 -04:00
USING: base64 io.encodings.ascii io.encodings.string kernel
2017-06-08 22:02:13 -04:00
sequences splitting strings tools.test ;
2007-09-20 18:09:08 -04:00
2015-07-02 20:28:17 -04:00
{ "abcdefghijklmnopqrstuvwxyz" } [ "abcdefghijklmnopqrstuvwxyz" ascii encode >base64 base64> ascii decode
2007-09-20 18:09:08 -04:00
] unit-test
2015-07-02 20:28:17 -04:00
{ "" } [ "" ascii encode >base64 base64> ascii decode ] unit-test
{ "a" } [ "a" ascii encode >base64 base64> ascii decode ] unit-test
{ "ab" } [ "ab" ascii encode >base64 base64> ascii decode ] unit-test
{ "abc" } [ "abc" ascii encode >base64 base64> ascii decode ] unit-test
{ "abcde" } [ "abcde" ascii encode >base64 3 cut "\r\n" swap 3append base64> ascii decode ] unit-test
2008-06-16 06:16:21 -04:00
! From http://en.wikipedia.org/wiki/Base64
2015-07-02 20:28:17 -04:00
{ "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" }
2008-06-16 06:16:21 -04:00
[
"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."
2009-03-06 15:10:53 -05:00
ascii encode >base64 >string
2008-06-16 06:16:21 -04:00
] unit-test
2015-07-02 20:28:17 -04:00
{ "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\r\nIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\r\ndGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\r\ndWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\r\nZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" }
2009-01-13 19:50:16 -05:00
[
"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."
2009-03-06 15:10:53 -05:00
ascii encode >base64-lines >string
2009-01-13 19:50:16 -05:00
] unit-test
2009-04-09 20:50:25 -04:00
[ { 33 52 17 40 12 51 33 43 18 33 23 } base64> ]
[ malformed-base64? ] must-fail-with
2017-06-08 22:02:13 -04:00
{
{
B{ 123 34 97 108 103 34 58 34 72 83 50 53 54 34 125 }
B{ 123 34 115 117 98 34 58 34 74 111 101 34 125 }
B{
138 151 175 68 219 145 63 161 223 148 111 28 20 169 230
80 251 114 166 187 145 11 135 219 212 53 173 160 178 250
217 38
}
}
} [
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKb2UifQ.ipevRNuRP6HflG8cFKnmUPtypruRC4fb1DWtoLL62SY"
"." split [ base64> ] map
2017-07-03 15:00:44 -04:00
] unit-test