Guest User

Untitled

a guest
Jan 19th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. const encrypt = (text, key) => {
  2. return Array
  3. .from(text)
  4. .reduce((acc, char) => acc.concat(char.charCodeAt().toString(2)), [])
  5. .map(bin => '0'.repeat(8 - bin.length) + bin )
  6. .map(binary => binary ^ key)
  7. .join(' ')
  8. };
  9.  
  10. const decrypt = (binary, key) => {
  11. return binary
  12. .split(' ')
  13. .map(bin => parseInt((bin ^ key),2))
  14. .map(bin => String.fromCharCode(bin))
  15. .join('')
  16. };
  17.  
  18. const secret = 'akunamatata';
  19. const binary = encrypt('hello', secret);
  20. decrypt(binary, secret);
Add Comment
Please, Sign In to add comment