1/* RC4 symmetric cipher encryption/decryption 2 * Copyright (c) 2006 by Ali Farhadi. 3 * released under the terms of the Gnu Public License. 4 * see the GPL for details. 5 * 6 * Email: ali[at]farhadi[dot]ir 7 * Website: http://farhadi.ir/ 8 */ 9 10/** 11 * Encrypt given plain text using the key with RC4 algorithm. 12 * All parameters and return value are in binary format. 13 * 14 * @param string key - secret key for encryption 15 * @param string pt - plain text to be encrypted 16 * @return string 17 */ 18function rc4Encrypt(key, pt) { 19 s = new Array(); 20 for (var i=0; i<256; i++) { 21 s[i] = i; 22 } 23 var j = 0; 24 var x; 25 for (i=0; i<256; i++) { 26 j = (j + s[i] + key.charCodeAt(i % key.length)) % 256; 27 x = s[i]; 28 s[i] = s[j]; 29 s[j] = x; 30 } 31 i = 0; 32 j = 0; 33 var ct = ''; 34 for (var y=0; y<pt.length; y++) { 35 i = (i + 1) % 256; 36 j = (j + s[i]) % 256; 37 x = s[i]; 38 s[i] = s[j]; 39 s[j] = x; 40 ct += String.fromCharCode(pt.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]); 41 } 42 return ct; 43} 44 45/** 46 * Decrypt given cipher text using the key with RC4 algorithm. 47 * All parameters and return value are in binary format. 48 * 49 * @param string key - secret key for decryption 50 * @param string ct - cipher text to be decrypted 51 * @return string 52*/ 53function rc4Decrypt(key, ct) { 54 return rc4Encrypt(key, ct); 55} 56 57/* Hexadecimal conversion methods. 58 * Copyright (c) 2006 by Ali Farhadi. 59 * released under the terms of the Gnu Public License. 60 * see the GPL for details. 61 * 62 * Email: ali[at]farhadi[dot]ir 63 * Website: http://farhadi.ir/ 64 */ 65 66//Encodes data to Hex(base16) format 67function hexEncode(data){ 68 var b16_digits = '0123456789abcdef'; 69 var b16_map = new Array(); 70 for (var i=0; i<256; i++) { 71 b16_map[i] = b16_digits.charAt(i >> 4) + b16_digits.charAt(i & 15); 72 } 73 74 var result = new Array(); 75 for (var i=0; i<data.length; i++) { 76 result[i] = b16_map[data.charCodeAt(i)]; 77 } 78 79 return result.join(''); 80} 81 82//Decodes Hex(base16) formated data 83function hexDecode(data){ 84 var b16_digits = '0123456789abcdef'; 85 var b16_map = new Array(); 86 for (var i=0; i<256; i++) { 87 b16_map[b16_digits.charAt(i >> 4) + b16_digits.charAt(i & 15)] = String.fromCharCode(i); 88 } 89 if (!data.match(/^[a-f0-9]*$/i)) return false;// return false if input data is not a valid Hex string 90 91 if (data.length % 2) data = '0'+data; 92 93 var result = new Array(); 94 var j=0; 95 for (var i=0; i<data.length; i+=2) { 96 result[j++] = b16_map[data.substr(i,2)]; 97 } 98 99 return result.join(''); 100}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.