Last active
          March 5, 2021 01:42 
        
      - 
      
 - 
        
Save SparK-Cruz/fa2a769094da5ea59752aa259a101f2a to your computer and use it in GitHub Desktop.  
    Lib/function for One Time Padding strings
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (() => { | |
| const OTP = (() => { | |
| function xorStrings(a, b) { | |
| let c = ""; | |
| for (let i = 0; i < a.length; i++) | |
| c += String.fromCharCode(a.charCodeAt(i) ^ b.charCodeAt(i)); | |
| return c; | |
| } | |
| function padkey(key, length) { | |
| let padded = key; | |
| while (padded.length < length) | |
| padded += key; | |
| return padded.substr(0, length); | |
| } | |
| function transform(message, key) { | |
| return xorStrings(message, padkey(key, message.length)); | |
| } | |
| return transform; | |
| })(); | |
| if (typeof window !== 'undefined') { | |
| window.OTP = OTP; | |
| } | |
| if (typeof module !== 'undefined') { | |
| module.exports = OTP; | |
| } | |
| })(); | 
      
      
  Author
  
  
      
          
      
      
            SparK-Cruz
  
      
      
      commented 
        Mar 5, 2021 
      
    
  
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment