Skip to content

Commit 6ccf593

Browse files
save file
1 parent 47e2a48 commit 6ccf593

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```
2+
3+
var tiny = {};
4+
tiny.encrypt = (message,key)=>btoa([...message].reduce((a,c,i)=>a+tiny.xor(c,key,i),''));
5+
tiny.decrypt = (encrypted,key)=>[...atob(encrypted)].reduce((a,e,i)=>a+tiny.xor(e,key,i),'');
6+
tiny.xor = (c,key,i)=>tiny.char(tiny.code(c)^tiny.code(key[i%key.length]));
7+
tiny.code = v=>v.charCodeAt(0);
8+
tiny.char = v=>String.fromCharCode(v);
9+
10+
var encrypted = tiny.encrypt('helloworld','sky')
11+
console.log(encrypted);
12+
var decrypted = tiny.decrypt(encrypted,'sky');
13+
console.log(decrypted);
14+
15+
```

0 commit comments

Comments
 (0)