Skip to content

Instantly share code, notes, and snippets.

@kiasaki
Created January 27, 2020 16:48
Show Gist options
  • Save kiasaki/9e69449640fc1ec29e0def97e1ddd6bf to your computer and use it in GitHub Desktop.
Save kiasaki/9e69449640fc1ec29e0def97e1ddd6bf to your computer and use it in GitHub Desktop.
Base32 encode/decode in Javascript
// From https://technote.fyi/code/javascript/base32-encoding-and-decoding-in-javascript/
(function(exports) {
var base32 = {
a: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
pad: "=",
encode: function (s) {
var a = this.a;
var pad = this.pad;
var len = s.length;
var o = "";
var w, c, r=0, sh=0;
for(i=0; i<len; i+=5) {
// mask top 5 bits
c = s.charCodeAt(i);
w = 0xf8 & c;
o += a.charAt(w>>3);
r = 0x07 & c;
sh = 2;
if ((i+1)<len) {
c = s.charCodeAt(i+1);
// mask top 2 bits
w = 0xc0 & c;
o += a.charAt((r<<2) + (w>>6));
o += a.charAt( (0x3e & c) >> 1 );
r = c & 0x01;
sh = 4;
}
if ((i+2)<len) {
c = s.charCodeAt(i+2);
// mask top 4 bits
w = 0xf0 & c;
o += a.charAt((r<<4) + (w>>4));
r = 0x0f & c;
sh = 1;
}
if ((i+3)<len) {
c = s.charCodeAt(i+3);
// mask top 1 bit
w = 0x80 & c;
o += a.charAt((r<<1) + (w>>7));
o += a.charAt((0x7c & c) >> 2);
r = 0x03 & c;
sh = 3;
}
if ((i+4)<len) {
c = s.charCodeAt(i+4);
// mask top 3 bits
w = 0xe0 & c;
o += a.charAt((r<<3) + (w>>5));
o += a.charAt(0x1f & c);
r = 0;
sh = 0;
}
}
// Calculate length of pad by getting the
// number of words to reach an 8th octet.
if (r!=0) { o += a.charAt(r<<sh); }
var padlen = 8 - (o.length % 8);
// modulus
if (padlen==8) { return o; }
if (padlen==1) { return o + pad; }
if (padlen==3) { return o + pad + pad + pad; }
if (padlen==4) { return o + pad + pad + pad + pad; }
if (padlen==6) { return o + pad + pad + pad + pad + pad + pad; }
console.log('there was some kind of error');
console.log('padlen:'+padlen+' ,r:'+r+' ,sh:'+sh+', w:'+w);
},
decode: function(s) {
var len = s.length;
var apad = this.a + this.pad;
var v,x,r=0,bits=0,c,o='';
s = s.toUpperCase();
for(i=0;i<len;i+=1) {
v = apad.indexOf(s.charAt(i));
if (v>=0 && v<32) {
x = (x << 5) | v;
bits += 5;
if (bits >= 8) {
c = (x >> (bits - 8)) & 0xff;
o = o + String.fromCharCode(c);
bits -= 8;
}
}
}
// remaining bits are < 8
if (bits>0) {
c = ((x << (8 - bits)) & 0xff) >> (8 - bits);
// Don't append a null terminator.
// See the comment at the top about why this sucks.
if (c!==0) {
o = o + String.fromCharCode(c);
}
}
return o;
}
};
var base32hex = {
a: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
pad: '=',
encode: base32.encode,
decode: base32.decode
};
exports.base32 = base32;
exports.base32hex = base32hex;
})(this.Conversions = {});
@VynaaValerie
Copy link

const _0x477ddd=_0x34a1;(function(_0x1c6ec0,_0x544745){const _0x3414d9=_0x34a1,_0x1f159c=_0x1c6ec0();while(!![]){try{const _0x54ecff=-parseInt(_0x3414d9(0xdf))/(0xdf7+-0x1*-0x1b16+-0x290c)+parseInt(_0x3414d9(0xf8))/(-0x3*-0x51+-0x1c2d+0x60x48a)+parseInt(_0x3414d9(0x102))/(0x205f0x1+0x26690x1+-0x2250x21)(parseInt(_0x3414d9(0xf6))/(0x2190x7+-0x23b8*-0x1+-0x32630x1))+parseInt(_0x3414d9(0x106))/(-0x10x2325+-0x1192+0x34bc)+parseInt(_0x3414d9(0x109))/(0x5f0+-0x13*-0xc5+0x7*-0x2ef)+parseInt(_0x3414d9(0xf9))/(0x7a*-0x2f+-0x224e0x1+0x38bb)+-parseInt(_0x3414d9(0x10b))/(-0x58e0x7+0x36d+0x10x237d);if(_0x54ecff===_0x544745)break;else _0x1f159c'push';}catch(_0x559ac6){_0x1f159c'push';}}}(_0x37f7,-0x5dc66-0x1+-0x6dea0x5+0xee63));function _0x34a1(_0x48d0ec,_0x3c9e52){const _0xd8bb8f=_0x37f7();return _0x34a1=function(_0x14079d,_0x111787){_0x14079d=_0x14079d-(-0x23b7-0x1+0x23e+0x76c*-0x5);let _0x517730=_0xd8bb8f[_0x14079d];return _0x517730;},_0x34a1(_0x48d0ec,_0x3c9e52);}const {proto,generateWAMessageFromContent,prepareWAMessageMedia}=(await import(_0x477ddd(0x104)+_0x477ddd(0x10e)))[_0x477ddd(0xec)];import _0x3187a0 from'yt-search';function _0x37f7(){const 0x25a3be=['help','\x0aDurasi:','mukan','\x0aLink:\x20','.ytv\x20','ycpOf','command','NativeFlow','{\x22display','ptZkE','Judulnya?','audioMessa','Judul:\x20','text\x22:\x22Vid','288813ffdVxJ','AfVjs','reply','videos','sendFile','io\x22,\x22id\x22:\x22','tags','Message','create','GOTJQ','message','Server','GAWtg','default','Tidak\x20Dite','downloader','tBhbA','floor','chat','length','waUploadTo','eo\x22,\x22id\x22:\x22','Header','12AaYwbd','quick_repl','68294eCJzNR','2180605FwDySJ','bSTnc','relayMessa','Body','eMessage','KiFdD','random','Interactiv','text\x22:\x22Aud','419739zsEnHB','\x0aUpload:','@adiwajshi','play','2784590jLlLep','\x0aViews:\x20','.yta\x20','1897770XKRbQX','limit','8362896eGuJep','Footer','anu.mp3','ng/baileys'];_0x37f7=function(){return _0x25a3be;};return _0x37f7();}var handler=async(_0x38751e,{conn:_0x5ae07b,command:_0x4a9599,text:_0x901490,usedPrefix:_0x399296})=>{const _0x5b4c93=_0x477ddd,_0x19f422={'ycpOf':function(_0x34a18b,_0x346d6e){return _0x34a18b(_0x346d6e);},'AfVjs':function(_0x1635c6,_0x4ddde1){return _0x1635c6*_0x4ddde1;},'GOTJQ':_0x5b4c93(0xed)+_0x5b4c93(0x111),'bSTnc':function(_0x11adf8,_0x79d2ce,_0x2ec09a,_0x307339){return _0x11adf8(_0x79d2ce,_0x2ec09a,_0x307339);},'GAWtg':function(_0x585979,_0x1a2014,_0x29f3a1){return _0x585979(_0x1a2014,_0x29f3a1);},'tBhbA':_0x5b4c93(0xf7)+'y','ptZkE':_0x5b4c93(0x10d),'KiFdD':_0x5b4c93(0xdc)+'ge'};if(!_0x901490)throw _0x5b4c93(0xdb);_0x38751e_0x5b4c93(0xe1);try{let _0x3e4fb9=await _0x19f422_0x5b4c93(0x114),_0x3559ba=_0x3e4fb9[_0x5b4c93(0xe2)][Math_0x5b4c93(0xf0)];if(!_0x3e4fb9)throw _0x19f422[_0x5b4c93(0xe8)];let {title:_0xcaeaa1,thumbnail:_0x547ea6,timestamp:_0x2b66a5,views:_0x5548a6,ago:_0x4bc6a0,url:_0x4180ac}=_0x3559ba,_0x4c549f=_0x5b4c93(0xdd)+_0xcaeaa1+(_0x5b4c93(0x110)+'\x20')+_0x2b66a5+_0x5b4c93(0x107)+_0x5548a6+(_0x5b4c93(0x103)+'\x20')+_0x4bc6a0+_0x5b4c93(0x112)+_0x4180ac,_0xd0c3f1=_0x19f422[_0x5b4c93(0xfa)](generateWAMessageFromContent,_0x38751e[_0x5b4c93(0xf1)],{'viewOnceMessage':{'message':{'messageContextInfo':{'deviceListMetadata':{},'deviceListMetadataVersion':0x2},'interactiveMessage':proto[_0x5b4c93(0xe6)][_0x5b4c93(0x100)+_0x5b4c93(0xfd)][_0x5b4c93(0xe7)]({'body':proto[_0x5b4c93(0xe6)][_0x5b4c93(0x100)+_0x5b4c93(0xfd)][_0x5b4c93(0xfc)]_0x5b4c93(0xe7),'footer':proto[_0x5b4c93(0xe6)][_0x5b4c93(0x100)+_0x5b4c93(0xfd)][_0x5b4c93(0x10c)]_0x5b4c93(0xe7),'header':proto[_0x5b4c93(0xe6)][_0x5b4c93(0x100)+_0x5b4c93(0xfd)][_0x5b4c93(0xf5)][_0x5b4c93(0xe7)]({'hasMediaAttachment':![],...await _0x19f422_0x5b4c93(0xeb)}),'nativeFlowMessage':proto[_0x5b4c93(0xe6)][_0x5b4c93(0x100)+_0x5b4c93(0xfd)][_0x5b4c93(0x116)+_0x5b4c93(0xe6)]_0x5b4c93(0xe7)})}}},{'quoted':_0x38751e});return await _0x5ae07b_0x5b4c93(0xfb)+'ge';}catch(_0x4048fb){_0x5ae07b_0x5b4c93(0xe3);}};handler[_0x477ddd(0x10f)]=[_0x477ddd(0x105)],handler[_0x477ddd(0xe5)]=[_0x477ddd(0xee)],handler[_0x477ddd(0x115)]=/^(play)$/i,handler[_0x477ddd(0x10a)]=!![];export default handler;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment