/ Published in: JavaScript
A custom made encoding method
Expand |
Embed | Plain Text
function KASXencode(x){ var ar_1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '-', '.', '\'', '"', '\\', '/', ' ', '(', ')', '$', '%', '*', '@', '&', '^', '?', '!'], ar_2 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], len = x.length, split = x.split(''), returnval = '', i, g, num; for(i = 0; i < split.length; i++){ for(g = 0; g < ar_1.length;g++){ if(ar_1[g]===split[i]){ if((i%2)===1){ num = (len+g)%26; returnval += ar_2[num]; } else{ num = (Math.abs(g-len))%26; returnval += ar_2[num]; } } } for(g = 0; g < ar_2.length;g++){ if(ar_2[g]===split[i]){ if((i%2)===1){ num = (len+g)%26; returnval += ar_1[num]; } else{ num = (Math.abs(g-len))%26; returnval += ar_1[num]; } } } } return returnval; }
You need to login to post a comment.
