Last active
July 17, 2018 16:14
-
-
Save justinbowes/072e1eb808f9084baf0f88f83f9cbf90 to your computer and use it in GitHub Desktop.
AES256 encrypt/decrypt bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<h2>Drag link to bookmarks bar</h2> | |
<a href='javascript:(function(e){const t={split(e){const t=[];for(let r=0;r<e.length;){const n=e.charCodeAt(r);let o;n>=55296&&n<=56319?(o=(n-55296<<10)+(e.charCodeAt(r+1)-56320+65536),r+=2):(o=n,++r),t.push(String.fromCodePoint(o))}return t},encode(e){const t=5-e.length %25 5;let r="";e=String.fromCharCode(t)+"\0".repeat(t-1)+e;for(let t=0;t<e.length;t+=5){let o=e.substr(t,5).split("").map(n).reduce((e,t)=>256*e+t,0);for(let e=0;e<4;++e){const e=o %25 1024;o=Math.floor(o/1024),r+=this.map[e]}}return r},decode(e){const t=this.split(e);let r="";for(let e=0;t.length;++e){let n=[];for(;n.length<4;)n.unshift(this.map.indexOf(t.shift()));let o=n.reduce((e,t)=>1024*e+t,0),l="";for(let t=0;t<5;++t){let r=o %25 256;o=Math.floor(o/256),l=String.fromCharCode(r)+l,0==e&&4==t&&(l=l.substring(r))}r+=l}return r}};t.map=t.split("♈♉♊♋♌♍♎♏♐♑♒♓⚛⛓⛔🄰🄱🄲🄳🄴🄵🄶🄷🄸🄹🄺🄻🄼🄽🄾🄿🅀🅁🅂🅃🅄🅅🅆🅇🅈🅉🅐🅑🅒🅓🅔🅕🅖🅗🅘🅙🅚🅛🅜🅝🅞🅟🅠🅡🅢🅣🅤🅥🅦🅧🅨🅩🆎🆏🆑🆒🆓🆔🆕🆖🆗🆘🆙🆚🌀🌁🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌌🌍🌎🌏🌐🌑🌒🌓🌔🌕🌖🌗🌘🌙🌚🌛🌜🌝🌞🌟🌠🌡🌤🌥🌦🌧🌨🌩🌪🌫🌬🌭🌮🌯🌰🌱🌲🌳🌴🌵🌶🌷🌸🌹🌺🌻🌼🌽🌾🌿🍀🍁🍂🍃🍄🍅🍆🍇🍈🍉🍊🍋🍌🍍🍎🍏🍐🍑🍒🍓🍔🍕🍖🍗🍘🍙🍚🍛🍜🍝🍞🍟🍠🍡🍢🍣🍤🍥🍦🍧🍨🍩🍪🍫🍬🍭🍮🍯🍰🍱🍲🍳🍴🍵🍶🍷🍸🍹🍺🍻🍼🍽🍾🍿🎀🎁🎂🎃🎄🎅🎆🎇🎈🎉🎊🎋🎌🎍🎎🎏🎐🎑🎒🎓🎖🎗🎙🎚🎛🎞🎟🎠🎡🎢🎣🎤🎥🎦🎧🎨🎩🎪🎫🎬🎭🎮🎯🎰🎱🎲🎳🎴🎵🎶🎷🎸🎹🎺🎻🎼🎽🎾🎿🏀🏁🏂🏃🏄🏅🏆🏇🏈🏉🏊🏋🏌🏍🏎🏏🏐🏑🏒🏓🏔🏕🏖🏗🏘🏙🏚🏛🏜🏝🏞🏟🏠🏡🏢🏣🏤🏥🏦🏧🏨🏩🏪🏫🏬🏭🏮🏯🏰🏳🏴🏵🏷🏸🏹🏺🏻🏼🏽🏾🏿🐀🐁🐂🐃🐄🐅🐆🐇🐈🐉🐊🐋🐌🐍🐎🐏🐐🐑🐒🐓🐔🐕🐖🐗🐘🐙🐚🐛🐜🐝🐞🐟🐠🐡🐢🐣🐤🐥🐦🐧🐨🐩🐪🐫🐬🐭🐮🐯🐰🐱🐲🐳🐴🐵🐶🐷🐸🐹🐺🐻🐼🐽🐾🐿👀👁👂👃👄👅👆👇👈👉👊👋👌👍👎👏👐👑👒👓👔👕👖👗👘👙👚👛👜👝👞👟👠👡👢👣👤👥👦👧👨👩👪👫👬👭👮👯👰👱👲👳👴👵👶👷👸👹👺👻👼👽👾👿💀💁💂💃💄💅💆💇💈💉💊💋💌💍💎💏💐💑💒💓💔💕💖💗💘💙💚💛💜💝💞💟💠💡💢💣💤💥💦💧💨💩💪💫💬💭💮💯💰💱💲💳💴💵💶💷💸💹💺💻💼💽💾💿📀📁📂📃📄📅📆📇📈📉📊📋📌📍📎📏📐📑📒📓📔📕📖📗📘📙📚📛📜📝📞📟📠📡📢📣📤📥📦📧📨📩📪📫📬📭📮📯📰📱📲📳📴📵📶📷📸📹📺📻📼📽📿🔀🔁🔂🔃🔄🔅🔆🔇🔈🔉🔊🔋🔌🔍🔎🔏🔐🔑🔒🔓🔔🔕🔖🔗🔘🔙🔚🔛🔜🔝🔞🔟🔠🔡🔢🔣🔤🔥🔦🔧🔨🔩🔪🔫🔬🔭🔮🔯🔰🔱🔲🔳🔴🔵🔶🔷🔸🔹🔺🔻🔼🔽🕉🕊🕋🕌🕍🕎🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧🕯🕰🕳🕴🕵🕶🕷🕸🕹🕺🖇🖊🖋🖌🖍🖐🖕🖖🖤🖥🖨🖱🖲🖼🗂🗃🗄🗑🗒🗓🗜🗝🗞🗡🗣🗨🗯🗳🗺🗻🗼🗽🗾🗿😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯😰😱😲😳😴😵😶😷😸😹😺😻😼😽😾😿🙀🙁🙂🙃🙄🙅🙆🙇🙈🙉🙊🙋🙌🙍🙎🙏🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏🚐🚑🚒🚓🚔🚕🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟🚠🚡🚢🚣🚤🚥🚦🚧🚨🚩🚪🚫🚬🚭🚮🚯🚰🚱🚲🚳🚴🚵🚶🚷🚸🚹🚺🚻🚼🚽🚾🚿🛀🛁🛂🛃🛄🛅🛋🛌🛍🛎🛏🛐🛑🛒🛠🛡🛢🛣🛤🛥🛩🛫🛬🛰🛳🛴🛵🛶🛷🛸🤐🤑🤒🤓🤔🤕🤖🤗🤘🤙🤚🤛🤜🤝🤞🤟🤠🤡🤢🤣🤤🤥🤦🤧🤨🤩🤪🤫🤬🤭🤮🤯🤰🤱🤲🤳🤴🤵🤶🤷🤸🤹🤺🤼🤽🤾🥀🥁🥂🥃🥄🥅🥇🥈🥉🥊🥋🥌🥐🥑🥒🥓🥔🥕🥖🥗🥘🥙🥚🥛🥜🥝🥞🥟🥠🥡🥢🥣🥤🥥🥦🥧🥨🥩🥪🥫🦀🦁🦂🦃🦄🦅🦆🦇🦈🦉🦊🦋🦌🦍🦎🦏🦐🦑🦒🦓🦔🦕🦖🦗🧀🧐🧑🧒🧓🧔🧕🧖🧗🧘🧙🧚🧛🧜🧝🧞🧟🧠🧡🧢🧣🧤🧥🧦");const r={encode:e=>unescape(encodeURIComponent(e)),decode:e=>decodeURIComponent(escape(e))},n=e=>e.charCodeAt(0),o=e.getSelection,l=String.fromCharCode,s=16,a=255,c=t.decode("🌔♈♈🄱🔧😰🛶💬🐢♈🌄👺🛵💥🧔🍢💵🔛🅓🚎💏🅒🌲🐠🌥🚍😭🕒🚊🛍🤕😶🅛💮🧦🎋💓🌍🔛🕟🚇🏩🐋🍷👕🐼👄🙀😟🅟🏠🄽🐾🏽🚋🍑🔖😏👜🍣🖥😩🏛🔽🌄🦑📭🍚🎴🚬⛔🚨🥚🖤👱🗳🎂🙊🍗🎛🚧🗜😮🚧💴🐌🚜🏬🍒🄰🧜♑🍂🎃🏒🕰👷📸💎🔆🎷🆏👝😏🄴🚧🏤🥫🄸💌💴🥊🐟🤥🔳🙆🌴🎋👒🐯🕘🌽👽🏺🄵🥇🌟📜🦐😪💛🛸🎾🕚🤶🍻🥄🍧💇🍄🌬🐴🏑👅👈💖🌶🤵🌇🔗🎢🚹🖍🐙🕷🦃🏦📄🤾🅃😜🏩🔧🌥🥙🦂🚥🛴🖱🄰🍚📩📉🎵🌳👔👁💩🚹🐿💳🥔💔😸👉🔲🏎🔜🧐🤷👬🔎🤢📲🐍🚝🦖🛥🍃🕍🏥🌗🕋🏁🙊🏦😹🅥").split("").map(n),f=[0,1,2,4,8,16,32,64,128,27,54].map(e=>[e,0,0,0]),p=(e,t)=>Array.apply(null,{length:e}).map((e,r)=>t(r)),i=e=>p(32,t=>((e,t)=>e.charCodeAt(t))(e,t)),d=e=>{for(let t=0;t<4;++t)e[t]=c[e[t]];return e},g=e=>{const t=e[0];for(let t=0;t<3;++t)e[t]=e[t+1];return e[3]=t,e},u=e=>{for(let t=0;t<4;t++)for(let r=0;r<4;r++)e[t][r]=c[e[t][r]];return e},h=e=>{const t=[,,,];for(let r=1;r<4;r++){for(let n=0;n<4;n++)t[n]=e[r][(n+r) %25 4];for(let n=0;n<4;n++)e[r][n]=t[n]}return e},m=e=>{for(let t=0;t<4;t++){const r=[,,,],n=[,,,];for(let o=0;o<4;++o)r[o]=e[o][t],n[o]=128&e[o][t]?e[o][t]<<1^283:e[o][t]<<1;e[0][t]=n[0]^r[1]^n[1]^r[2]^r[3],e[1][t]=r[0]^n[1]^r[2]^n[2]^r[3],e[2][t]=r[0]^r[1]^n[2]^r[3]^n[3],e[3][t]=r[0]^n[0]^r[1]^r[2]^n[3]}return e},C=(e,t,r)=>{for(let n=0;n<4;n++)for(let o=0;o<4;o++)e[n][o]^=t[4*r+o][n];return e},A=(e,t)=>{const r=t.length/4-1;let n=[[],[],[],[]];for(let t=0;t<s;++t)n[t %25 4][Math.floor(t/4)]=e[t];n=C(n,t,0);for(let e=1;e<r;e++)n=C(m(h(u(n))),t,e);return n=C(h(u(n)),t,r),p(s,e=>n[e %25 4][Math.floor(e/4)])},y=e=>{const t=e.length/4,r=4*(t+7),n=new Array(r);for(let r=0;r<t;++r)n[r]=p(4,t=>e[4*r+t]);for(let e=t;e<r;++e){let r=n[e-1].slice();for(let t=0;t<4;t++)r[t]=n[e-1][t];if(e %25 t==0){r=d(g(r));for(let n=0;n<4;n++)r[n]^=f[e/t][n]}else t>6&&e %25 t==4&&(r=d(r));n[e]=p(4,o=>n[e-t][o]^r[o])}return n},M=(e,t=!0)=>{const r=o();if(!r.getRangeAt||!r.rangeCount)return;range=r.getRangeAt(0),range.deleteContents(),fragment=range.createContextualFragment(e);const n=fragment.firstChild,l=fragment.lastChild;range.insertNode(fragment),t&&(n&&(range.setStartBefore(n),range.setEndAfter(l)),r.removeAllRanges(),r.addRange(range))},S=(e,n)=>t.encode(((e,t)=>{const r=e.length,n=i(t),o=A(n,y(n)),c=(new Date).getTime(),f=[];for(let e=0;e<4;++e)f[e]=Math.floor(c/1e3)>>>8*e&a,f[e+4]=c %25 1e3&a;const d=l.apply(null,f),g=y(o.concat(o.slice(0,16))),u=Math.ceil(r/s);return d+p(u,t=>{for(let e=0;e<4;++e)f[15-e]=t>>>8*e&a,f[11-e]=t/4294967296>>>8*e;const n=A(f,g),o=t<u-1?s:(r-1) %25 s+1;return l.apply(null,p(o,r=>n[r]^e.charCodeAt(t*s+r)))}).join("")})(r.encode(e),r.encode(n))),R=(e,o)=>((e,t)=>{const o=i(t),c=A(o,y(o)),f=e.slice(0,8).split("").map(e=>n(e)),d=y(c.concat(c.slice(0,16))),g=Math.ceil((e.length-8)/s),u=p(g,t=>e.slice(8+t*s,8+t*s+s));return r.decode(u.map((e,t)=>{for(let e=0;e<4;++e)f[15-e]=t>>>8*e&a,f[11-e]=(t+1)/4294967296-1>>>8*e&a;const r=A(f,d);return l.apply(null,e.split("").map((e,t)=>r[t]^n(e)))}).join(""))})(t.decode(e),r.encode(o));return{go:()=>{const r=(()=>o().toString())(),n=r||e.prompt("Input");if(!n)return;const l=prompt("Passphrase","****");if(!l)return;const s=t.split(n.substr(0,2));if(t.map.indexOf(s[0])>=0){const t=R(n,l);r?M(t):e.prompt("[Decrypted text]",t)}else{const t=S(n,l);r?M(t):e.prompt("[Encrypted text]",t)}}}})(window).go();'>AES-256 🔄</a> | |
<ul> | |
<li>Click bookmarklet to encode arbitrary text at prompt</li> | |
<li>Highlight text and click bookmarklet to encrypt</li> | |
<li>Highlight encrypted text and click bookmarklet to decrypt</li> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment