JavaScript 276 ==================== function R(len){var k='',r,i=0 for(;i<len;i++)r=Math.floor(Math.random()*26),k+=String.fromCharCode(r+65) return k } function X(s,k,d){var o='',i=0,a,b,c while(i<s.length)a=s.charCodeAt(i)-65,b=k.charCodeAt(i++)-65,c=d?26+(a-b):a+b,o+=String.fromCharCode((c%26)+65) return o } Usage: var str = "HELLOWORLD"; var key = R(str.length); var enc = X(str, key, false); console.log(enc); console.log(X(enc,key, true));