# Andy's Net

## XECryption Decryptor

Made specifically for Realistic Mission 6 on Hack This Site, I had a lot of fun making this!

If you're looking for answers, while this will tell you, I would highly advise against using it for such. It's so much more beneficial to work it out yourself!

The goal behind this mission is to decrypt a message to retreive the contents, you're told it is encrypted using the XECryption algorithm.

So after learning about the encryption, I came up with this little tool to help work it out for me.

You'll want to use the Previous button over the Next, the script starts from the highest possible password value, working backwards is much quicker than starting at 0, or of course, the "Find Answer" button...

The "Find Answer" button works by looking for the most common value and assuming it is the space key (this works very well for letters). You can edit and add your own XECryption code and see if it'll work.

0

## A look at the code

``````const xecDecryption = {
theCode: '',
valueArray: [],

// Retrieve the code.
retrieveCode: function(){
this.theCode = document.getElementById('theCode').value;

// Turn code into array.
let theCodeArray = this.theCode.split( '.' );

// Remove first '.';
theCodeArray.shift();

this.valueArray = [];

// Add 3 groups of numbers together and store value of each into array.
for( let i = 0; i < theCodeArray.length; i += 3 ){
this.valueArray.push( parseInt( theCodeArray[ i ] ) + parseInt( theCodeArray[ i+1 ] ) + parseInt( theCodeArray[ i+2 ] ) );
}
// Get smallest number, this will be our starting point for decryption. (huge boost in finding the correct value)
let min = Math.min.apply( null, this.valueArray ),
maxValue = min-1;

}

this.decrypt();
},

// Decrypt the code and output the value.
decrypt: function(){

// Convert number to array.
let newArray = String( this.thePassword ).split( '' );

let theText = '';

for( let i = 0; i < this.valueArray.length; i++ ){
theText += String.fromCharCode( this.valueArray[ i ] - this.thePassword );
//theText += String( this.valueArray[ i ] - this.thePassword );
}

document.getElementById( 'textEl' ).value = theText;
},

increase: function( num = 1 ){
if ( this.thePassword > 2700 ){
}
this.decrypt();
},

decrease: function( num = 1 ){
if ( this.thePassword < 0 ){
}
this.decrypt();
},

// Attempt to find the most readable answer by finding the most common letter ' ', (space), ascii value 32.

// Loop through the array and find the most common value, then work out the difference from space to that value, thus returning our password value.
let i = 0,
max = 0,
freqArray = [];

for(; i < this.valueArray.length; i++ ){
freqArray[ this.valueArray[ i ] ] = freqArray[ this.valueArray[ i ] ] + 1 || 0;

if (freqArray[ this.valueArray[ i ] ] > max){
max = freqArray[ this.valueArray[ i ] ];

// Store current value, minus the space key ascii value (32), this is our most likely password value;
this.thePassword = this.valueArray[ i ] - 32;
}
}
this.decrypt();
}
};``````