web-common-resource/terminal/smartxKs/base64.js

1 line
1.4 KiB
JavaScript
Raw Normal View History

2024-08-20 12:11:35 +00:00
var Base64={toBase64Table:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),base64Pad:"=",encode:function(r){"use strict";for(var e="",a=Base64.toBase64Table,t=r.length,o=t%3,n=0;n<t-2;n+=3)e+=a[r[n]>>2],e+=a[((3&r[n])<<4)+(r[n+1]>>4)],e+=a[((15&r[n+1])<<2)+(r[n+2]>>6)],e+=a[63&r[n+2]];var s=0;return 2===o?(s=t-o,e+=a[r[s]>>2],e+=a[((3&r[s])<<4)+(r[s+1]>>4)],e+=a[(15&r[s+1])<<2],e+=a[64]):1===o&&(s=t-o,e+=a[r[s]>>2],e+=a[(3&r[s])<<4],e+=a[64],e+=a[64]),e},toBinaryTable:[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1],decode:function(r,e){"use strict";e=void 0!==e?e:0;var a,t,o=Base64.toBinaryTable,n=Base64.base64Pad,s=0,c=0,i=r.indexOf("=")-e;i<0&&(i=r.length-e),t=3*(i>>2)+Math.floor(i%4/1.5),a=new Array(t);for(var l=0,d=e;d<r.length;d++){var h=o[127&r.charCodeAt(d)],B=r.charAt(d)===n;-1!==h?(c=c<<6|h,(s+=6)>=8&&(s-=8,B||(a[l++]=c>>s&255),c&=(1<<s)-1)):console.error("Illegal character code "+r.charCodeAt(d)+" at position "+d)}if(s)throw err=new Error("Corrupted base64 string"),err.name="Base64-Error",err;return a}};