Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const encrypt = (text, key) => {
- return Array
- .from(text)
- .reduce((acc, char) => acc.concat(char.charCodeAt().toString(2)), [])
- .map(bin => '0'.repeat(8 - bin.length) + bin )
- .map(binary => binary ^ key)
- .join(' ')
- };
- const decrypt = (binary, key) => {
- return binary
- .split(' ')
- .map(bin => parseInt((bin ^ key),2))
- .map(bin => String.fromCharCode(bin))
- .join('')
- };
- const secret = 'akunamatata';
- const binary = encrypt('hello', secret);
- decrypt(binary, secret);
Add Comment
Please, Sign In to add comment