Skip to content

Commit d62010a

Browse files
authored
Merge pull request #17 from Procaseycash/redudancy-improvement
Redundancy and Duplicate Improvement
2 parents e2ab6fc + 19e18c3 commit d62010a

File tree

3 files changed

+14
-83
lines changed

3 files changed

+14
-83
lines changed

package/app.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,21 @@ const encrypta = (st: string, salt: string, d = 1) => {
1414
};
1515

1616
export const encrypt = (
17-
param: Object | string | number | any[],
18-
salt: string,
19-
d = 1
17+
param: Object | string | number | any[],
18+
salt: string,
19+
d = 1
2020
) => {
21-
const hashSalt: number = hashFun(salt.trim().substring(0, 20));
22-
return JSON.stringify(param)
23-
.split('')
24-
.map((c, i) =>
25-
String.fromCharCode(c.charCodeAt(0) + configNum(hashSalt, i) * d)
26-
)
27-
.join('')
28-
.replace(/\\/g, 'blacard')
29-
.replace(/\//g, 'danger')
30-
.replace(/"/g, 'killer')
31-
.replace(/'/g, 'terror')
32-
.replace(/ /g, 'blankart')
33-
.replace(/{/g, 'alpha')
34-
.replace(/}/g, 'mega')
35-
.replace(/`/g, 'omega');
21+
return encrypta(JSON.stringify(param), salt, d)
22+
.replace(/\\/g, 'blacard')
23+
.replace(/\//g, 'danger')
24+
.replace(/"/g, 'killer')
25+
.replace(/'/g, 'terror')
26+
.replace(/ /g, 'blankart')
27+
.replace(/{/g, 'alpha')
28+
.replace(/}/g, 'mega')
29+
.replace(/`/g, 'omega');
3630
};
31+
3732
export const decrypt = (str: string, salt: string) => {
3833
let encryption = encrypta(
3934
str

package/hashFun.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("hashFun", () => {
77
it("should return 1100101", () => {
88
expect(hashFun("a")).toBe(1100101);
99
});
10-
it("should return 1100101", () => {
10+
it("should return 1100011010100000", () => {
1111
expect(hashFun("Secret*@+-1234")).toBe(1100011010100000);
1212
});
1313
});

package/hashFun.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -227,70 +227,6 @@ export const hashFun = (secret: string) => {
227227
case ',':
228228
hash = hash + 75;
229229
break;
230-
case '-':
231-
hash = hash + 0;
232-
break;
233-
case '.':
234-
hash = hash + 0;
235-
break;
236-
case '/':
237-
hash = hash + 0;
238-
break;
239-
case ':':
240-
hash = hash + 0;
241-
break;
242-
case ';':
243-
hash = hash + 0;
244-
break;
245-
case '<':
246-
hash = hash + 0;
247-
break;
248-
case '=':
249-
hash = hash + 0;
250-
break;
251-
case '>':
252-
hash = hash + 0;
253-
break;
254-
case '?':
255-
hash = hash + 0;
256-
break;
257-
case '@':
258-
hash = hash + 0;
259-
break;
260-
case '[':
261-
hash = hash + 0;
262-
break;
263-
case '\\':
264-
hash = hash + 0;
265-
break;
266-
case ']':
267-
hash = hash + 0;
268-
break;
269-
case '^':
270-
hash = hash + 0;
271-
break;
272-
case '_':
273-
hash = hash + 0;
274-
break;
275-
case '`':
276-
hash = hash + 0;
277-
break;
278-
case '{':
279-
hash = hash + 0;
280-
break;
281-
case '|':
282-
hash = hash + 0;
283-
break;
284-
case '}':
285-
hash = hash + 0;
286-
break;
287-
case '~':
288-
hash = hash + 0;
289-
break;
290-
291-
default:
292-
hash = hash + 0;
293-
break;
294230
}
295231
charGen.push(hash);
296232
return hash & hash;

0 commit comments

Comments
 (0)