Guest User

Untitled

a guest
May 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. ((root, factory) => {
  2. if (typeof define === 'function' && define.amd) {
  3. // AMD. Register as an anonymous module.
  4. define([], factory)
  5. } else if (typeof module === 'object' && module.exports) {
  6. // Node. Does not work with strict CommonJS.
  7. module.exports = factory()
  8. } else {
  9. // Browser globals (root is window)
  10. root.deobfuscate = factory()
  11. }
  12. })(typeof self !== 'undefined' ? self : this, () => {
  13. const delay = ms => new Promise(resolve => { setTimeout(resolve, ms) })
  14. const range = (begin, end) => [...Array(1 + end - begin).keys()].map(index => begin + index)
  15. const toCharCode = (...string) => string.map(char => char.charCodeAt(0))
  16. const charRange = (begin, end) => String.fromCharCode(...range(...toCharCode(begin, end)))
  17. const choose = array => array[Math.floor(Math.random() * array.length)]
  18. const lookup = o => key => o[key]
  19.  
  20. // Just return a value to define the module export.
  21. return async ({
  22. string = '',
  23. duration = 1,
  24. fps = 60,
  25. random = charRange('\u0020', '\u007e'),
  26. next = choose,
  27. render
  28. } = {}) => {
  29. const { length } = string
  30. const getters = Array(length).fill(() => choose(random))
  31. const obfuscated = [...getters.keys()]
  32. const timeout = duration * 1000 / length
  33. const charAt = lookup(string)
  34. const interval = setInterval(() => {
  35. render(getters.map((getter, index) => getter(index)).join(''), false)
  36. }, 1000 / fps)
  37.  
  38. let indices = Object.values(obfuscated)
  39.  
  40. while (indices.length > 0) {
  41. await delay(timeout)
  42. const index = next(indices)
  43. getters[index] = charAt
  44. delete obfuscated[index]
  45. indices = Object.values(obfuscated)
  46. }
  47.  
  48. clearInterval(interval)
  49. render(string)
  50. }
  51. })
Add Comment
Please, Sign In to add comment