Skip to content

Commit

Permalink
Hallelujah!
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinAlbs committed Nov 5, 2016
1 parent af14d32 commit 85788d0
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
7 changes: 6 additions & 1 deletion base64example.txt.base123
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
DT d84€€5HΔ@€L€Œ`@ €ƒ@π€¤ƄbQ y@ƒ€?Og{ow}:=w[m}>Ypƒypx=Zm7c?_ztz?WIwm6_No7eDb5Hd6H^/li~Lv;kSi~} %ywtzs%2_juO[f gIdwMVo gAnmFcZ*SiwIˆsbA&}fsjOg}2)ү[6+$Α;+σ!kʦ^n~%Y€à:%A*jkOQB10QE 1}Mw=.TAӬn67Ye6G&<pʵJPu6O}Q^@9MN~¹*s4Xuuol5 ChEyBGx<u!p2z'xn7Υ$ td9k7/Pu0y MO^{ÚҘeҾ `kC^ǫwA9%(DJ%`V<)1ML|FLa$i{Q!st~g5a`ϐJ`4RfNF8vh1~C|.#-FƐh4grfpƇY!`]c^b tF*b;)|1[ƻ&}feaD8iN<3Ebhp*MKXzR7FG(tKaj-MdP#qm?=X *7Úi{S'ӗnN}`Ð:h.KY5pC]60ә!5Q (5q1l)sk;E:Se(ó1IOcq] xXJ~ρxiK#Ar@) 8ö5g_DZoJL W1mVRMy10 >w He'7g[b1X{ϰ`W,lGA#i5θ vep2of#Wt!s>)E 3kP5y!!.! 3LvgjgӶDe!goo_~N+$NwH9Un<6'#(! L|AB<0hTtsF(ΉEU b5fC:9TΆ E9@WA*Ɠ/[Z!OtW6I$u&Z/@F<6,X<v |[K^{7N=db<F!C4X[2Wh-[QSӥlo4m66{jjqC; A[P)7Z@Dpm0ө cB3v_gckҀ=IyO!$orkd$& vƘ5C06#;$1%pveotbfB ,m) v C$sIDd[[++]cdzZw=LNE)2UxBZJoE b*]-w#Y};`cmU%ixPҞdT-v1W)'+2 WIF*s7 F1#OVgXR{j[@*pFu}s ,gYZ78#:+lr8I'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c/#/hk~fiRg )l v6xa8YPM +[G$2ΰn˵'36ΦFRdiu>-oqFQR2z>ps,z+Vq=r>[7,rY gUumnu<$Dsi'GZ$Ez1N/{%vq2ouӲρ NPe#fe@@T-IPG_PCO>0 @zVf8Ua$AL;NS32xu`1Ea(Ipd1pW9-J2ozf}naӱbgο)C}Y'/D?n|ǭ!y |e5`ӺP|$N.ON /dʆw[M_> hq3vi wJ?Hz6M i>O7kT:m?70-bsq3mv!hXMycs$|z= aIT€€E'd" />
81 changes: 81 additions & 0 deletions base64example2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<html>
<head>
<meta charset='utf-8' />
</head>
<body>

<img data-b123="DT d84€€5HΔ@€L€Œ`@ €ƒ@π€¤ƄbQ y@ƒ€?Og{ow}:=w[m}>Ypƒypx=Zm7c?_ztz?WIwm6_No7eDb5Hd6H^/li~Lv;kSi~} %ywtzs%2_juO[f gIdwMVo gAnmFcZ*SiwIˆsbA&}fsjOg}2)ү[6+$Α;+σ!kʦ^n~%Y€à:%A*jkOQB10QE 1}Mw=.TAӬn67Ye6G&<pʵJPu6O}Q^@9MN~¹*s4Xuuol5 ChEyBGx<u!p2z'xn7Υ$ td9k7/Pu0y MO^{ÚҘeҾ `kC^ǫwA9%(DJ%`V<)1ML|FLa$i{Q!st~g5a`ϐJ`4RfNF8vh1~C|.#-FƐh4grfpƇY!`]c^b tF*b;)|1[ƻ&}feaD8iN<3Ebhp*MKXzR7FG(tKaj-MdP#qm?=X *7Úi{S'ӗnN}`Ð:h.KY5pC]60ә!5Q (5q1l)sk;E:Se(ó1IOcq] xXJ~ρxiK#Ar@) 8ö5g_DZoJL W1mVRMy10 >w He'7g[b1X{ϰ`W,lGA#i5θ vep2of#Wt!s>)E 3kP5y!!.! 3LvgjgӶDe!goo_~N+$NwH9Un<6'#(! L|AB<0hTtsF(ΉEU b5fC:9TΆ E9@WA*Ɠ/[Z!OtW6I$u&Z/@F<6,X<v |[K^{7N=db<F!C4X[2Wh-[QSӥlo4m66{jjqC; A[P)7Z@Dpm0ө cB3v_gckҀ=IyO!$orkd$& vƘ5C06#;$1%pveotbfB ,m) v C$sIDd[[++]cdzZw=LNE)2UxBZJoE b*]-w#Y};`cmU%ixPҞdT-v1W)'+2 WIF*s7 F1#OVgXR{j[@*pFu}s ,gYZ78#:+lr8I'U6QE20%bm>,.nc),g =_#43{ҭ4b<0-1HI*KROnGW-}/ ^pwV'to)<X)MVC&^ h5#[}60,2lmǟfbBuQbe.$[sP=# /Ag~QC+kg~)iKJ;vcM$e7 x_X^Mv)b3` *8G.gzUc)cktyT )JzV)-C)lΛ(Dva$ d=8nndU3^!-?)*BZ^5U#AOI{˟^1m~B$^Ef B`;UHlpDqcXkRH( JTxnwwWoSnu0eVJxxr/lW~Z0[xXQN.#/˓#-RBz CW*|inet2m<[)@Iҋr|MOBgNjǤ;%txtOEw'OO2s}i>LE4u uaA&> @a,:mΰb{;#¬.(Vgjlb1dΎxRW~#o#>DejkbPqb5xP(EE;K AzLsb9&iydc}OUCtvO{q@)k3[n%:JEQΖIb.40Tx`m@i)N[Nu<UY WF#-ff ʓ7#%y?MM[Ygk96'35ydra:wfedүp*ӅCK^}H%'E__np9`Sk^X7ϻ-G?Hc/#/hk~fiRg )l v6xa8YPM +[G$2ΰn˵'36ΦFRdiu>-oqFQR2z>ps,z+Vq=r>[7,rY gUumnu<$Dsi'GZ$Ez1N/{%vq2ouӲρ NPe#fe@@T-IPG_PCO>0 @zVf8Ua$AL;NS32xu`1Ea(Ipd1pW9-J2ozf}naӱbgο)C}Y'/D?n|ǭ!y |e5`ӺP|$N.ON /dʆw[M_> hq3vi wJ?Hz6M i>O7kT:m?70-bsq3mv!hXMycs$|z= aIT€€E'd" />

<script>
let specials = [
0 // null
, 10 // newline
, 13 // carriage return
, 34 // double quote
, 92 // backslash
]
, kHeader = 0b00001111 // Enforce odd and greater than 13 to avoid special chars.
, kShortened = 0b01000000
;
// Bitwise order of operations (according to MDN)
// ~ << >> >>> & ^ |
// Subtraction (-) comes before all.
// Base for web function.
function decodeString(strData) {
let decoded = [];
let curByte = 0;
let bitOfByte = 0;
let header = strData.charCodeAt(0);

function push7(byte) {
byte <<= 1;
// Align this byte to offset for current byte.
curByte = curByte | byte >>> bitOfByte;
// Explanation:
bitOfByte += 7;
if (bitOfByte >= 8) {
decoded.push(curByte);
bitOfByte -= 8;
// Now, take the remainder, left shift by what has been taken.
curByte = byte << 7 - bitOfByte & 255;
}
}

for (var i = 1; i < strData.length; i++) {
let c = strData.charCodeAt(i);

// Check for a leading 1 bit, indicating a two-byte character.
if (c > 127) {
// Note, the charCodeAt will give the codePoint, thus
// 0b110xxxxx 0b10yyyyyy will give => xxxxxyyyyyy

var specialIndex = c >>> 8 & 7; // 7 = 0b111. Note, >>> precedes &
push7(specials[specialIndex]);

// Skip the remainder only if this is the last character and the header says so.
if (i == strData.length - 1 && (header & kShortened)) continue;
push7(c & 0x7F); // Note order of operations.
} else {
// Regular ascii.
push7(c);
}
}
return decoded;
}

let base64 = atob("iVBORw0KGgoAAAANSUhEUgAAAGYAAABmCAMAAAAOARRQAAAAkFBMVEX////MAADLAAD//Pz+9/f66en+9vb/+vrPAAD88PD21tb439/109P65OT32tr87e3yxMTWRkbSLy/YT0/pnZ3rp6fxv7/QJSXkf3/genrmlZXwurrPHh7eYmLzycnebW3jhYXODg7tsbHaVFTVPT3kjY3PFBTfc3PVPz/WSkrcXl7bZWXSIiLssrLooaHWNTXt35LZAAAGB0lEQVRoge1a55aiShCGIhgIoiIoMkgQMfv+b3erqkG5s3Nm5yzl/to6Z5wGtT8qh1bT/tE/egOZs78AcqubSx167wWxqgKQ9EXyThR/Dzqh4MvSfxuKt0SU+FLpBPTI5Da26+h1YeSIsvNn3vZIOAtXDGUDcfC8GuHeFa+8E+GcpVB2JKSncFZ4pYzZnyNMJYSiTT7ooefT9nINcOBFQMysDSkYzTozjt/B6GP6H8XI1sYUQ0Gx7Qnn5HcwgJwFB7KE9gM3SwTHexDOkY2qxO1PxjbF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cOuq+ad2XoWBnmW15bUwDpWTcFheXwmFmz4RHPO1BRWQG7SkunjpPik+6efPKMuf3S+mRWho71HIOuEzBTPhcDCsdbUTDF7doy4BYuUVs+rZiCsciId4pV/xwOjOFze9G+iZdWsHioccTXwIN0FBIPFOxXcsWbg+pnMFiJuU2nzkx/S0+rD6dp/viaIwFOtnb3JXUqKSooi0nEuaMKgXwSwbYGlTOtiJ3V5VsmUFeMjHrc2YWNJgxzckjJlkvl/NCzbdnPrctk7Nr5/5OWF13zZcn+4v4KrkWHLvBPshKHTkot+/uH8HOCnrvWDrdF7Wg47+RjXo1+jX+zaaWcWp2Ehh7s28YXFmhNEq7Z+OGSMkTDcN6pwrMsRbDz6JMWjUsmkf1fLd/GNRpMvQ58O4czaz0EV1gfF7yfW26zlZGZ6vXbu6iHiQebic9KeOBtGUhiL6Yzl/tL24st5Drc5IoIudQylUebKFgHYFRbJoR79CGTnvmCCAR9VszgdVwpIMx3Ops2XjrgYxcKiSW4ZGPCu5BrTsoCy3gvWYl93DsJw6VuccWdE/Unof0eGskE6+I/Kmtx74K2oQRryL+ZWoHBc9UPiScunzhK/ITGhu9ubffGhegyVI8WZztpPjO46U/kem01BpBvp7fWaqOtr9uwPAluLnx/s9psQW7f0Og3Ym+QuMfzSA/gP09FnS+GSFqAAAAABJRU5ErkJggg==");


function decode(el) {
base123 = el.getAttribute('data-b123');
inflated = new Uint8Array(decodeString(base123));
var blob = new Blob([inflated], {type: "image/png"});
var url = URL.createObjectURL(blob);
el.src = url;
}

decode(document.querySelectorAll('[data-b123]')[0]);

</script>
</body>
</html>
23 changes: 22 additions & 1 deletion test/testAll.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Simple correctness unit tests of encoding and decoding functions.

let assert = require('assert')
, base64 = require('base-64')
, tester = require('./tester')
, testData = require('./testData')
, base123 = require('../base123')
;

Expand Down Expand Up @@ -58,4 +58,25 @@ tester.addTest('specialBytes', () => {
testEncodeDecode(rawData, expectedEncoding);
});


tester.addTest('base64Img', () => {
// Just test that encoding and decoding gives back original.
let rawData = [0,0,0,102,0,0];
let encoded = base123.encode(rawData);
let decoded = base123.decode(encoded);
assert.deepStrictEqual(rawData, decoded);
// FIX
});

tester.addTest('base64Img', () => {
// Just test that encoding and decoding gives back original.
let buf = Buffer.from(testData.base64.img1, 'base64');
let rawData = [];
for (val of buf.values()) rawData.push(val);
let encoded = base123.encode(rawData);
let decoded = base123.decode(encoded);
assert.deepStrictEqual(rawData, decoded);
// FIX
});

tester.run();
4 changes: 3 additions & 1 deletion test/testData.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85788d0

Please sign in to comment.