88 lines
2.2 KiB
JavaScript
88 lines
2.2 KiB
JavaScript
|
$(document).ready(() => {
|
||
|
$('#encrypter-tab-switch a[data-toggle="tab"]').on('shown.bs.tab', (e) => {
|
||
|
const targetName = e.target.attributes['aria-controls'].nodeValue;
|
||
|
window.history.pushState({
|
||
|
"html": $('#encryption-container').html().toString()
|
||
|
}, targetName, '/tools/encrypter/' + targetName);
|
||
|
});
|
||
|
|
||
|
window.onpopstate = (e) => {
|
||
|
if (e.state) {
|
||
|
$('#encryption-container').html(e.state.html);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
$($('#encrypter-tab-switch > li.active').removeClass('active').children()[0]).click();
|
||
|
|
||
|
const adgfvxObj = new adgfvxClass();
|
||
|
adgfvxObj.init();
|
||
|
|
||
|
const atbashObj = new atbashClass('atbash');
|
||
|
|
||
|
});
|
||
|
|
||
|
class encrypterClass {
|
||
|
constructor(name) {
|
||
|
this.encrypting = true;
|
||
|
this.input = $('#' + name + '-input');
|
||
|
this.output = $('#' + name + '-output');
|
||
|
this.input.on('keyup', this.typing);
|
||
|
}
|
||
|
|
||
|
abstract typing() {
|
||
|
const input = this.input.val();
|
||
|
if (this.encrypting)
|
||
|
this.output.val(this.encrypt(input));
|
||
|
else
|
||
|
this.output.val(this.decrypt(input));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class adgfvxClass {
|
||
|
init() {
|
||
|
this.encrypting = true;
|
||
|
this.input = $('#adfgvx-input');
|
||
|
this.output = $('#adfgvx-output');
|
||
|
this.input.on('keyup', () => this.typing());
|
||
|
}
|
||
|
|
||
|
encrypt(input) {
|
||
|
let encrypted = input;
|
||
|
return encrypted;
|
||
|
}
|
||
|
|
||
|
decrypt(input) {
|
||
|
let decrypted = input;
|
||
|
return decrypted;
|
||
|
}
|
||
|
|
||
|
typing() {
|
||
|
const input = this.input.val();
|
||
|
if (this.encrypting)
|
||
|
this.output.val(this.encrypt(input));
|
||
|
else
|
||
|
this.output.val(this.decrypt(input));
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
class atbashClass extends encrypterClass {
|
||
|
encrypt(input) {
|
||
|
let encrypted = '';
|
||
|
for(let char of input) {
|
||
|
const charCode = char.charCodeAt(0);
|
||
|
if(charCode >= 97 && charCode <= 122) {
|
||
|
encrypted += String.fromCharCode(122 - charCode + 97);
|
||
|
} else if(charCode >= 65 && charCode <= 90) {
|
||
|
encrypted += String.fromCharCode(90 - charCode + 65);
|
||
|
} else {
|
||
|
encrypted += char;
|
||
|
}
|
||
|
}
|
||
|
return encrypted;
|
||
|
}
|
||
|
|
||
|
decrypt(input) {
|
||
|
|
||
|
}
|
||
|
}
|