﻿// Trim prototype
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.startsWith = function(str) {
    return (this.match("^" + str) == str);
}

String.prototype.endsWith = function(str) {
    return (this.match(str + "$") == str);
}

// Encryption
function encrypt(source, key) {
    var result = "";

    for (i = 0; i < source.length; ++i) {
        result += String.fromCharCode(key ^ source.charCodeAt(i));
    }

    return result;
}


function decrypt(source, key) {
    var result = "";

    for (i = 0; i < source.length; i++) {
        result += String.fromCharCode(key ^ source.charCodeAt(i));
    }

    return result;
}