Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ((root, factory) => {
- if (typeof define === 'function' && define.amd) {
- // AMD. Register as an anonymous module.
- define([], factory)
- } else if (typeof module === 'object' && module.exports) {
- // Node. Does not work with strict CommonJS.
- module.exports = factory()
- } else {
- // Browser globals (root is window)
- root.deobfuscate = factory()
- }
- })(typeof self !== 'undefined' ? self : this, () => {
- const delay = ms => new Promise(resolve => { setTimeout(resolve, ms) })
- const range = (begin, end) => [...Array(1 + end - begin).keys()].map(index => begin + index)
- const toCharCode = (...string) => string.map(char => char.charCodeAt(0))
- const charRange = (begin, end) => String.fromCharCode(...range(...toCharCode(begin, end)))
- const choose = array => array[Math.floor(Math.random() * array.length)]
- const lookup = o => key => o[key]
- // Just return a value to define the module export.
- return async ({
- string = '',
- duration = 1,
- fps = 60,
- random = charRange('\u0020', '\u007e'),
- next = choose,
- render
- } = {}) => {
- const { length } = string
- const getters = Array(length).fill(() => choose(random))
- const obfuscated = [...getters.keys()]
- const timeout = duration * 1000 / length
- const charAt = lookup(string)
- const interval = setInterval(() => {
- render(getters.map((getter, index) => getter(index)).join(''), false)
- }, 1000 / fps)
- let indices = Object.values(obfuscated)
- while (indices.length > 0) {
- await delay(timeout)
- const index = next(indices)
- getters[index] = charAt
- delete obfuscated[index]
- indices = Object.values(obfuscated)
- }
- clearInterval(interval)
- render(string)
- }
- })
Add Comment
Please, Sign In to add comment