How to use decryptAscii method in wpt

Best JavaScript code snippet using wpt

encryptor.service.ts

Source:encryptor.service.ts Github

copy

Full Screen

1export class Encryptor {2 encryptascii(str: any) {3 const key = process.env.ENCKEY;4 const dataKey: any = {};5 for (let i = 0; i < key.length; i++) {6 dataKey[i] = key.substr(i, 1);7 }8 let strEnc = '';9 let nkey = 0;10 const jml = str.length;11 for (let i = 0; i < parseInt(jml); i++) {12 strEnc =13 strEnc +14 this.hexEncode(str[i].charCodeAt(0) + dataKey[nkey].charCodeAt(0));15 if (nkey === Object.keys(dataKey).length - 1) {16 nkey = 0;17 }18 nkey = nkey + 1;19 }20 return strEnc.toUpperCase();21 }22 decryptascii(str: any) {23 if (str) {24 const key = process.env.ENCKEY;25 const dataKey: any = {};26 for (let i = 0; i < key.length; i++) {27 dataKey[i] = key.substr(i, 1);28 }29 let strDec = '';30 let nkey = 0;31 const jml = str.length;32 let i = 0;33 while (i < parseInt(jml)) {34 strDec =35 strDec +36 this.chr(this.hexdec(str.substr(i, 2)) - dataKey[nkey].charCodeAt(0));37 if (nkey === Object.keys(dataKey).length - 1) {38 nkey = 0;39 }40 nkey = nkey + 1;41 i = i + 2;42 }43 return strDec;44 }45 return true;46 }47 hexEncode(str: any) {48 let result = '';49 result = str.toString(16);50 return result;51 }52 hexdec(hex: any) {53 let str: any = '';54 str = parseInt(hex, 16);55 return str;56 }57 chr(asci: any) {58 let str = '';59 str = String.fromCharCode(asci);60 return str;61 }62 writeLocal(nama: any, data: any) {63 this.doEncrypt(data, ['kode_baki', 'nama_baki', 'kode_barang']);64 // return localStorage.setItem(nama, encryptascii(JSON.stringify(data)));65 }66 doEncrypt(dataBeforeCopy: any, ignore: any = []) {67 if (!Number(process.env.ENCRYPTION_MODE)) {68 return dataBeforeCopy;69 }70 if (!dataBeforeCopy) {71 return dataBeforeCopy;72 }73 if (74 typeof dataBeforeCopy === 'object' &&75 !(dataBeforeCopy instanceof Date)76 ) {77 const data = Array.isArray(dataBeforeCopy)78 ? [...dataBeforeCopy]79 : { ...dataBeforeCopy };80 Object.keys(data).map((x: any) => {81 const result = ignore.find((find: any) => find === x);82 if (!result) {83 if (Array.isArray(data[x])) {84 data[x] = data[x].map((y: any) => {85 if (typeof y === 'string') {86 return this.encryptascii(y);87 } else if (88 typeof data[x] === 'object' &&89 data[x] &&90 !(data[x] instanceof Date)91 ) {92 return this.doEncrypt(y, ignore);93 }94 return false;95 });96 } else {97 if (typeof data[x] === 'string' && data[x]) {98 data[x] = this.encryptascii(data[x]);99 } else if (typeof data[x] === 'number' && data[x]) {100 // Call Masking Number101 } else if (102 typeof data[x] === 'object' &&103 data[x] &&104 !(dataBeforeCopy instanceof Date)105 ) {106 data[x] = this.doEncrypt(data[x], ignore);107 }108 }109 }110 return false;111 });112 return data;113 } else if (typeof dataBeforeCopy === 'string') {114 const data = this.encryptascii(dataBeforeCopy);115 return data;116 }117 }118 doDecrypt(dataBeforeCopy: any, ignore: any = []) {119 if (!Number(process.env.ENCRYPTION_MODE)) {120 return dataBeforeCopy;121 }122 if (!dataBeforeCopy) {123 return dataBeforeCopy;124 }125 if (126 typeof dataBeforeCopy === 'object' &&127 !(dataBeforeCopy instanceof Date)128 ) {129 const data = Array.isArray(dataBeforeCopy)130 ? [...dataBeforeCopy]131 : { ...dataBeforeCopy };132 Object.keys(data).map((x: any) => {133 const result = ignore.find((find: any) => find === x);134 if (!result) {135 if (Array.isArray(data[x])) {136 data[x] = data[x].map((y: any) => {137 if (typeof y === 'string') {138 return this.decryptascii(y);139 } else if (140 typeof data[x] === 'object' &&141 data[x] &&142 !(data[x] instanceof Date)143 ) {144 return this.doDecrypt(y, ignore);145 }146 return false;147 });148 } else {149 // Real Encrypt150 if (typeof data[x] === 'string' && data[x]) {151 data[x] = this.decryptascii(data[x]);152 } else if (typeof data[x] === 'number' && data[x]) {153 // Call Unmasking Number()154 } else if (155 typeof data[x] === 'object' &&156 data[x] &&157 !(dataBeforeCopy instanceof Date)158 ) {159 data[x] = this.doDecrypt(data[x], ignore);160 }161 }162 }163 return false;164 });165 return data;166 } else if (typeof dataBeforeCopy === 'string') {167 const data = this.decryptascii(dataBeforeCopy);168 return data;169 }170 }171 doDecryptMiddleware() {172 return [173 (req: any, res: any, next: any) => {174 const isEnc = Number(req.headers.enc || '0');175 const ignoreFields = JSON.parse(req.headers.ignore || '[]');176 if (isEnc) {177 req.body = this.doDecrypt(req.body, ignoreFields);178 next();179 } else {180 next();181 }182 },183 ];184 }185 maskingNumber(number: any) {186 const numberString = String(number);187 const list = numberString.split('');188 return Number(189 list190 .map((data) => {191 if (data === '.') {192 return '.';193 } else {194 return String(Number(data) + 22);195 }196 })197 .join(''),198 );199 }200 unmaskingNumber(number: any) {201 const numberString = String(number);202 const list = numberString.split('.');203 return Number(204 list205 .map((data) => {206 const segment = data.split('').reduce((s, c) => {207 const l = s.length - 1;208 s[l] && s[l].length < 2 ? (s[l] += c) : s.push(c);209 return s;210 }, []);211 return segment212 .map((x) => {213 return x - 22;214 })215 .join('');216 })217 .join('.'),218 );219 }...

Full Screen

Full Screen

encrypt.js

Source:encrypt.js Github

copy

Full Screen

1const encryptascii = (str) => {2 let key = 'b3r4sput1h'3 let dataKey = {}4 for (let i = 0; i < key.length; i++) {5 dataKey[i] = key.substr(`${i}`, 1)6 }7 let strEnc = ''8 let nkey = 09 let jml = str.length10 for (let i = 0; i < parseInt(jml); i++) {11 strEnc = strEnc + hexEncode(str[i].charCodeAt(0) + dataKey[nkey].charCodeAt(0))12 if (nkey === Object.keys(dataKey).length - 1) {13 nkey = 014 }15 nkey = nkey + 116 }17 return strEnc.toUpperCase()18}19const decryptascii = (str) => {20 if (str !== null) {21 let key = 'b3r4sput1h'22 let dataKey = {}23 for (let i = 0; i < key.length; i++) {24 dataKey[i] = key.substr(`${i}`, 1)25 }26 let strDec = ''27 let nkey = 028 let jml = str.length29 let i = 030 while (i < parseInt(jml)) {31 strDec = strDec + chr(hexdec(str.substr(i, 2)) - dataKey[nkey].charCodeAt(0))32 if (nkey === Object.keys(dataKey).length - 1) {33 nkey = 034 }35 nkey = nkey + 136 i = i + 237 }38 return strDec39 }40}41const hexEncode = (str) => {42 var result = ''43 result = str.toString(16)44 return result45}46const hexdec = (hex) => {47 var str = ''48 str = parseInt(hex, 16)49 return str50}51const chr = (asci) => {52 var str = ''53 str = String.fromCharCode(asci)54 return str55}56function doEncrypt(data, ignore = []) {57 if (typeof data === 'object') {58 // eslint-disable-next-line59 Object.keys(data).map((x) => {60 const result = ignore.find((find) => find === x)61 if (!result) {62 if (Array.isArray(data[x])) {63 // eslint-disable-next-line64 data[x].map((y, i) => {65 if (typeof y === 'string') {66 data[x][i] = encryptascii(y)67 } else {68 doEncrypt(y, ignore)69 }70 })71 } else {72 if (typeof data[x] === 'string') {73 // console.log(data[x]);74 data[x] = encryptascii(data[x])75 } else if (typeof data[x] === 'number') {76 data[x] = maskingFunction(data[x])77 }78 }79 }80 })81 } else {82 if (typeof data === 'string') {83 // console.log(data);84 data = encryptascii(data)85 }86 }87 return data88}89function doDecrypt(data, ignore = []) {90 if (typeof data === 'object') {91 // eslint-disable-next-line92 Object.keys(data).map((x) => {93 const result = ignore.find((find) => find === x)94 if (!result) {95 if (Array.isArray(data[x])) {96 // eslint-disable-next-line97 data[x].map((y, i) => {98 if (typeof y === 'string') {99 data[x][i] = decryptascii(y)100 } else {101 doDecrypt(y, ignore)102 }103 })104 } else {105 if (typeof data[x] === 'string') {106 // console.log(data[x]);107 data[x] = decryptascii(data[x])108 } else if (typeof data[x] === 'number') {109 data[x] = unMaskingFunction(data[x])110 }111 }112 }113 })114 } else {115 if (typeof data === 'string') {116 // console.log(data);117 data = decryptascii(data)118 } else if (typeof data === 'number') {119 data = unMaskingFunction(data)120 }121 }122 return data123}124function maskingFunction(number) {125 const numberString = String(number)126 const list = numberString.split('')127 return Number(128 list129 .map((data) => {130 if (data === '.') {131 return '.'132 } else {133 // console.log(data);134 return String(Number(data) + 22)135 }136 })137 .join('') + '1'138 )139}140function unMaskingFunction(number) {141 const numberString = String(number).slice(0, String(number).length - 1)142 // console.log(numberString)143 const list = numberString.split('.')144 return Number(145 list146 .map((data) => {147 const segment = data.split('').reduce((s, c) => {148 let l = s.length - 1149 s[l] && s[l].length < 2 ? (s[l] += c) : s.push(c)150 return s151 }, [])152 return segment153 .map((x) => {154 // console.log(x);155 return x - 22156 })157 .join('')158 })159 .join('.')160 )161}162export const saveLocal = async (name, payload, ignore = []) => {163 return new Promise((resolve, reject) => {164 try {165 if (Array.isArray(payload)) {166 const hasil = payload.map((x) => doEncrypt(x, ignore))167 localStorage.setItem(name, JSON.stringify(hasil))168 resolve('Berhasil')169 } else if (typeof payload === 'string') {170 localStorage.setItem(name, encryptascii(payload))171 resolve('Berhasil')172 } else {173 localStorage.setItem(name, JSON.stringify(doEncrypt(payload, ignore)))174 resolve('Berhasil')175 }176 } catch (err) {177 reject(err)178 }179 })180}181export const getLocal = (name, ignore = []) => {182 return new Promise((resolve, reject) => {183 try {184 const result = localStorage.getItem(name)185 if (result === null) {186 resolve([])187 } else {188 if (result.includes('[')) {189 const hasil = JSON.parse(result).map((x) => doDecrypt(x, ignore))190 // console.log('INI DI ARRAY', hasil)191 resolve(hasil)192 } else if (result.includes('{')) {193 const hasil = doDecrypt(JSON.parse(result), ignore)194 // console.log('INI DI OBJECT', hasil)195 resolve(hasil)196 } else {197 resolve(doDecrypt(result, ignore))198 }199 }200 } catch (error) {201 console.log(error)202 reject(error)203 }204 })...

Full Screen

Full Screen

encryptor.ts

Source:encryptor.ts Github

copy

Full Screen

1import globalIgnore from '../constants/global-ignore';2export default class Encryptor {3 private encryptascii(str: any) {4 const key = process.env.ENCKEY;5 const dataKey: any = {};6 for (let i = 0; i < key.length; i++) {7 dataKey[i] = key.substr(i, 1);8 }9 let strEnc = '';10 let nkey = 0;11 const jml = str.length;12 for (let i = 0; i < parseInt(jml); i++) {13 strEnc = strEnc + this.hexEncode(str[i].charCodeAt(0) + dataKey[nkey].charCodeAt(0));14 if (nkey === Object.keys(dataKey).length - 1) {15 nkey = 0;16 }17 nkey = nkey + 1;18 }19 return strEnc.toUpperCase();20 }21 private decryptascii(str: any) {22 if (str) {23 const key = process.env.ENCKEY;24 const dataKey: any = {};25 for (let i = 0; i < key.length; i++) {26 dataKey[i] = key.substr(i, 1);27 }28 let strDec = '';29 let nkey = 0;30 const jml = str.length;31 let i = 0;32 while (i < parseInt(jml)) {33 strDec = strDec + this.chr(this.hexdec(str.substr(i, 2)) - dataKey[nkey].charCodeAt(0));34 if (nkey === Object.keys(dataKey).length - 1) {35 nkey = 0;36 }37 nkey = nkey + 1;38 i = i + 2;39 }40 return strDec;41 }42 }43 private hexEncode(str: any) {44 let result = '';45 result = str.toString(16);46 return result;47 }48 private hexdec(hex: any) {49 let str: any = '';50 str = parseInt(hex, 16);51 return str;52 }53 private chr(asci: any) {54 let str = '';55 str = String.fromCharCode(asci);56 return str;57 }58 doEncrypt(dataBeforeCopy: any, ignore: any = globalIgnore) {59 if (!dataBeforeCopy) {60 return dataBeforeCopy;61 }62 if (typeof dataBeforeCopy === 'object' && !(dataBeforeCopy instanceof Date)) {63 const data = Array.isArray(dataBeforeCopy) ? [...dataBeforeCopy] : { ...dataBeforeCopy };64 Object.keys(data).map((x: any) => {65 const result = ignore.find((find: any) => find === x);66 if (!result) {67 if (Array.isArray(data[x])) {68 data[x] = data[x].map((y: any) => {69 if (typeof y === 'string') {70 return this.encryptascii(y);71 } else if (typeof data[x] === 'object' && data[x] && !(data[x] instanceof Date)) {72 return this.doEncrypt(y, ignore);73 }74 return false;75 });76 } else {77 if (typeof data[x] === 'string' && data[x]) {78 data[x] = this.encryptascii(data[x]);79 } else if (typeof data[x] === 'number' && data[x]) {80 // Call Masking Number81 } else if (typeof data[x] === 'object' && data[x] && !(dataBeforeCopy instanceof Date)) {82 data[x] = this.doEncrypt(data[x], ignore);83 }84 }85 }86 return false;87 });88 return data;89 } else if (typeof dataBeforeCopy === 'string') {90 const data = this.encryptascii(dataBeforeCopy);91 return data;92 }93 }94 doDecrypt(dataBeforeCopy: any, ignore: any = globalIgnore) {95 if (!dataBeforeCopy) {96 return dataBeforeCopy;97 }98 if (typeof dataBeforeCopy === 'object' && !(dataBeforeCopy instanceof Date)) {99 const data = Array.isArray(dataBeforeCopy) ? [...dataBeforeCopy] : { ...dataBeforeCopy };100 Object.keys(data).map((x: any) => {101 const result = ignore.find((find: any) => find === x);102 if (!result) {103 if (Array.isArray(data[x])) {104 data[x] = data[x].map((y: any) => {105 if (typeof y === 'string') {106 return this.decryptascii(y);107 } else if (typeof data[x] === 'object' && data[x] && !(data[x] instanceof Date)) {108 return this.doDecrypt(y, ignore);109 }110 return false;111 });112 } else {113 // Real Encrypt114 if (typeof data[x] === 'string' && data[x]) {115 data[x] = this.decryptascii(data[x]);116 } else if (typeof data[x] === 'number' && data[x]) {117 // Call Unmasking Number()118 } else if (typeof data[x] === 'object' && data[x] && !(dataBeforeCopy instanceof Date)) {119 data[x] = this.doDecrypt(data[x], ignore);120 }121 }122 }123 return false;124 });125 return data;126 } else if (typeof dataBeforeCopy === 'string') {127 const data = this.decryptascii(dataBeforeCopy);128 return data;129 }130 }131 private maskingNumber(number: any) {132 const numberString = String(number);133 const list = numberString.split('');134 return Number(135 list136 .map((data) => {137 if (data === '.') {138 return '.';139 } else {140 return String(Number(data) + 22);141 }142 })143 .join(''),144 );145 }146 private unmaskingNumber(number: any) {147 const numberString = String(number);148 const list = numberString.split('.');149 return Number(150 list151 .map((data) => {152 const segment = data.split('').reduce((s, c) => {153 const l = s.length - 1;154 s[l] && s[l].length < 2 ? (s[l] += c) : s.push(c);155 return s;156 }, []);157 return segment158 .map((x) => {159 return x - 22;160 })161 .join('');162 })163 .join('.'),164 );165 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var WPT = require('./wpt');2var wpt = new WPT('API_KEY');3wpt.decryptAscii('encrypted_string', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var WPT = require('./wpt');11var wpt = new WPT('API_KEY');12wpt.getTestResults('test_id', function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var WPT = require('./wpt');20var wpt = new WPT('API_KEY');21wpt.getTestStatus('test_id', function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var WPT = require('./wpt');29var wpt = new WPT('API_KEY');30wpt.getTestStatusByUrl('test_url', function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var WPT = require('./wpt');38var wpt = new WPT('API_KEY');39wpt.getTestVideo('test_id', function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var WPT = require('./wpt');47var wpt = new WPT('API_KEY');48wpt.getTestVideoByUrl('test_url', function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var WPT = require('./wpt');56var wpt = new WPT('API_KEY');57wpt.getTestInfo('test_id', function(err, data) {58 if (err

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.decryptAscii('encrypted string');4var wpt = require('wpt');5var wpt = new wpt('API_KEY');6wpt.encryptAscii('string to encrypt');7var wpt = require('wpt');8var wpt = new wpt('API_KEY');9wpt.getLocations();10var wpt = require('wpt');11var wpt = new wpt('API_KEY');12wpt.getTests();13var wpt = require('wpt');14var wpt = new wpt('API_KEY');15wpt.getTestStatus('test id');16var wpt = require('wpt');17var wpt = new wpt('API_KEY');18wpt.getTestResults('test id');19var wpt = require('wpt');20var wpt = new wpt('API_KEY');21wpt.getTestResults('test id');22var wpt = require('wpt');23var wpt = new wpt('API_KEY');24wpt.getTestResults('test id', 'json');25var wpt = require('wpt');26var wpt = new wpt('API_KEY');27wpt.getTestResults('test id', 'xml');28var wpt = require('wpt');29var wpt = new wpt('API_KEY');30wpt.getTestResults('test id', 'har');31var wpt = require('wpt');32var wpt = new wpt('API_KEY');33wpt.getTestResults('test id', 'pages

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var str = wpt.decryptAscii("V2hhdCBpcyB0aGUgZGF0YT8=");3var wpt = require('./wpt.js');4var buffer = new Buffer("Hello World");5var str = wpt.encryptBinary(buffer);6var wpt = require('./wpt.js');7var str = wpt.decryptBinary("V2hhdCBpcyB0aGUgZGF0YT8=");8var wpt = require('./wpt.js');9var str = wpt.encryptFile("test.txt");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.2e2b4f2b4d4b4f4b4f4b4f4b4f4b4f4b');3wpt.decryptAscii('A.2e2b4f2b4d4b4f4b4f4b4f4b4f4b4f4b', function(err, data) {4 if (err) throw err;5 console.log(data);6});7### new WebPageTest(host, [key])8### WebPageTest#runTest(url, [options], callback)9* `options` - (optional) Options object10### WebPageTest#getLocations(callback)11### WebPageTest#getLocation(location, callback)12### WebPageTest#getTesters(callback)13### WebPageTest#getStatus(callback)14### WebPageTest#getTestStatus(testId, callback)15### WebPageTest#getTestResults(testId, callback)16### WebPageTest#getTestResultsByLabel(label, callback)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful