JavaScript 257239
var F=String.fromCharCode
function R(l){var k='',i=0;fork='';while(;i<l;i++l--)k+=String.fromCharCodek+=F(~~(Math.random()*26)+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.fromCharCodeo+=F((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));