Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class Encrpter {
- constructor(){
- this.data = new EncryptionData().encyption;
- this.encrypted_text = "";
- this.decrypted_text = "";
- this.encrypting = false;
- this.decrypting = false;
- this.illegal_characters = [34, 39, 40, 41, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 62, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126, 127];
- }
- encrypt_text(in_text){
- this.encrypting = true;
- //console.log(this.data);
- //console.log(in_text);
- //in_text = "Velkoz#1";
- this.encrypted_text = "";
- for(let i = 0; i < in_text.length; i++){
- let c = in_text[i].charCodeAt(0);
- //console.log(c);
- let random_pick = (1 + (Math.random()*4)).toFixed(0);
- //console.log(random_pick);
- this.encrypted_text = this.encrypted_text + this.data[c][random_pick];
- }
- //console.log(this.encrypted_text);
- this.encrypting = false;
- }
- decrypt_text(in_text){
- this.decrypting = true;
- //in_text = "y0fLNKCz4vKi8HUqskakf$WN&0wMvcn?R&HFX#nbN3xZagomis85njeZMjHS8ONJdm6iueWA6Xk";
- this.decrypted_text = "";
- let decrypters_chunk = [];
- let decrypters_character = [];
- //console.log(this.data);
- for(let i = 32; i < 134; i++){
- for(let j = 1; j < 6; j++){
- if(this.data[i] != undefined){
- if(this.data[i][j] != undefined){
- let encrypt = this.data[i][j];
- let temp = in_text;
- //console.log(i, encypt);
- while(temp.indexOf(encrypt) > -1){
- decrypters_chunk.push(encrypt);
- decrypters_character.push(String.fromCharCode(i));
- temp = temp.replace(encrypt,"");
- }
- }
- }
- }
- }
- //console.log(decrypters_chunk);
- //console.log(decrypters_character);
- while(decrypters_chunk.length > 0){
- for(let i = 0; i < decrypters_chunk.length; i++){
- let encrypt = decrypters_chunk[i];
- if(in_text.indexOf(encrypt) == 0){
- this.decrypted_text = '' + this.decrypted_text + '' + decrypters_character[i];
- in_text = '' + in_text.slice(encrypt.length, in_text.length + 1);
- decrypters_chunk.splice(i,1);
- decrypters_character.splice(i,1);
- break;
- }
- }
- }
- //console.log(this.decrypted_text);
- this.decrypting = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement