SHARE
TWEET

Untitled

a guest Aug 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class EmailObfuscator {
  2.   encodeEmail(email: string) {
  3.     const key = this.getRandomCode(33, 330)
  4.     let encodedString = key.toString(16)
  5.  
  6.     Array.from(email).forEach(item => encodedString += (item.charCodeAt(0) ^ key).toString(16))
  7.  
  8.     return encodedString
  9.   }
  10.  
  11.   decodeEmail(encodedString: string) {
  12.     let email = ''
  13.     const key = parseInt(encodedString.substr(0, 2), 16)
  14.  
  15.     for (let n = 2; encodedString.length - n; n += 2) {
  16.       const code = parseInt(encodedString.substr(n, 2), 16) ^ key
  17.       email += String.fromCharCode(code)
  18.     }
  19.  
  20.     return email
  21.   }
  22.  
  23.   private getRandomCode(min: number, max: number) {
  24.     return Math.floor(Math.random() * (max - min)) + min
  25.   }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top