spd-lib 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/img.py ADDED
@@ -0,0 +1,44 @@
1
+ from PIL import Image
2
+ def smoothstep(edge0, edge1, x):
3
+ # Scale, bias and saturate x to 0..1 range
4
+ t = max(0.0, min(1.0, (x - edge0) / (edge1 - edge0)))
5
+ # Evaluate polynomial
6
+ return t * t * (3 - 2 * t)
7
+ def invert_image_colors(image_path, output_path,output2_path):
8
+ # Open the image
9
+ img = Image.open(image_path).convert("RGB")
10
+ width, height = img.size
11
+
12
+ # Create a new image for the output
13
+ inverted_img = Image.new("RGB", (width, height))
14
+ i = 1
15
+ br=1
16
+ filter = [
17
+ 1,1,1,
18
+ 0,0,0,
19
+ 0,0,0
20
+ ]
21
+ # Loop through every pixel
22
+ for x in range(width):
23
+ for y in range(height):
24
+ r, g, b = img.getpixel((x, y))
25
+ # Subtract each color component from 255
26
+
27
+ m = ((255 - (r)*i) + (255 - (g)*i) + (255 -( b)*i))/3
28
+ m2 = (r+g+b)/3
29
+ co = smoothstep(0,255,m+m2)*255
30
+
31
+ r2 = smoothstep(0,255,r)
32
+ b2 = smoothstep(0,255,b)
33
+ g2 = smoothstep(0,255,g)
34
+ p_pixel = (round(co*r2),round(co*g2),round(co*b2))
35
+
36
+
37
+ inverted_img.putpixel((x, y), p_pixel)
38
+
39
+ # Save the result
40
+ inverted_img.save(output_path)
41
+ print(f"Inverted image saved to {output_path}")
42
+
43
+ # Example usage
44
+ invert_image_colors("new.jpeg", "output.jpg","output2.jpg")
package/obfuscate.js ADDED
@@ -0,0 +1,131 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const terser = require('terser');
4
+
5
+ const inputDir = path.join(__dirname, 'src'); // Your source code directory
6
+ const outputDir = path.join(__dirname, 'dist'); // The directory to output obfuscated code
7
+
8
+ // Create output directory if it doesn't exist
9
+ if (!fs.existsSync(outputDir)) {
10
+ fs.mkdirSync(outputDir);
11
+ }
12
+
13
+ // Read the source code from 'src' directory
14
+ fs.readdirSync(inputDir).forEach(async (file) => {
15
+ const filePath = path.join(inputDir, file);
16
+ const outputFilePath = path.join(outputDir, file);
17
+
18
+ // Read the file content
19
+ const fileContent = fs.readFileSync(filePath, 'utf8');
20
+ console.log(fileContent)
21
+
22
+ if (!fileContent) {
23
+ console.error(`Error: File ${file} is empty or couldn't be read.`);
24
+ return; // Skip this file if content is empty or not readable
25
+ }
26
+
27
+ // Log file being processed
28
+ console.log(`Processing file: ${file}`);
29
+
30
+ // Terser options for obfuscation
31
+ const terserOptions = {
32
+ mangle: {
33
+ // Ensure that class and function names are not mangled
34
+ reserved: ['SPD', 'setPassKey', 'addData', 'saveToFile', 'loadFromFile', 'extractData', 'saveData', 'loadFromString','setHash']
35
+ },
36
+ compress: {
37
+ // Enable compression to remove unnecessary code
38
+ drop_console: true // Optional: Remove console.log and similar calls
39
+ },
40
+ output: {
41
+ beautify: false,
42
+ comments: false
43
+ },
44
+
45
+ };
46
+
47
+ try {
48
+ // Obfuscate the content of the file with Terser
49
+ const result = await terser.minify(fileContent, {"compress":{
50
+ "booleans":true,
51
+ "arguments":true,
52
+ "arrows":true,
53
+ "collapse_vars":true,
54
+ "computed_props":true,
55
+ "booleans_as_integers":true,
56
+ "dead_code":true,
57
+ "drop_console":true,
58
+ "drop_debugger":true,
59
+ "if_return":true,
60
+ "join_vars":true,
61
+ "comparisons":true,
62
+ "conditionals":true,
63
+ "evaluate":true,
64
+ "expression":true,
65
+ "global_defs":true,
66
+ "defaults":true,
67
+ "hoist_funs":true,
68
+ "hoist_props":true,
69
+ "hoist_vars":true,
70
+ "directives":true,
71
+ "inline":true,
72
+ "module":true,
73
+ "loops":true,
74
+ "passes":true,
75
+ "typeofs":true,
76
+ "side_effects":true,
77
+ "switches":true,
78
+ "properties":true,
79
+ "reduce_funcs":true,
80
+ "reduce_vars":true,
81
+ "top_retain":false,
82
+ "toplevel":true,
83
+ "sequences":true,
84
+ "ie8":true,
85
+ "negate_iife":true,
86
+ },"mangle":{
87
+ "keep_classnames":true,
88
+ "keep_fnames":false,
89
+ "properties":false,
90
+
91
+
92
+ },"parse":{
93
+ "bare_returns":false,
94
+ "shebang":true
95
+ },
96
+ "format":{
97
+ "ascii_only":false,
98
+ "preserve_annotations":false,
99
+ "comments":false,
100
+ "keep_numbers":false,
101
+ "keep_quoted_props":false,
102
+ "wrap_func_args":true,
103
+ "shorthand":true,
104
+ "beautify":false
105
+
106
+ }});
107
+ console.log(result)
108
+
109
+ // Check if minification was successful and has a code
110
+ if (result.error) {
111
+ console.error(`Error minifying file ${file}:`, result.error);
112
+ return; // Skip writing this file if there was an error
113
+ }
114
+
115
+ if (!result.code) {
116
+ console.error(`No obfuscated code generated for ${file}.`);
117
+ return;
118
+ }
119
+
120
+ const obfuscatedCode = result.code;
121
+
122
+ // Write the obfuscated code to the 'dist' directory
123
+ fs.writeFileSync(outputFilePath, obfuscatedCode, 'utf8');
124
+ console.log(`Successfully obfuscated ${file}`);
125
+
126
+ } catch (err) {
127
+ console.error(`Error processing file ${file}:`, err);
128
+ }
129
+ });
130
+
131
+ console.log('Terser obfuscation complete.');
@@ -0,0 +1 @@
1
+ const fs=require("fs"),zlib=require("zlib"),sodium=require("libsodium-wrappers"),crypto=require("crypto"),argon2=require("argon2");class SPD{constructor(){this.data=[],this.keyPair,this.userKey,this.salt,this.hash="sha3-512",this.init()}async init(){await sodium.ready,this.keyPair=sodium.crypto_kx_keypair()}async setPassKey(a){await sodium.ready,this.init();const{pqcKey:t,salt:r}=await(new SPD).convertPasscodeToPQCKey(a),e=t.publicKey;this.userKey=e,this.salt=r}setHash(a){this.hash=a}async migrateFromFile(a,t){const r=await SPD.loadFromFile(a,t);r.extractData_OLD=async()=>new Promise((async(a,t)=>{try{await sodium.ready;let r={};this.data.forEach((async a=>{try{const t=sodium.crypto_secretbox_open_easy(a.data,a.nonce,this.userKey),e=zlib.inflateSync(t,{level:9}).toString("utf8");r[a.dataName]=await this.CSTI(e,a.dataType)}catch{t()}})),a(r)}catch{t()}}));const e=await r.extractData_OLD(),i=new SPD;await i.setPassKey(t);for(let a in e)await i.addData(a,e[a]);i.saveToFile(a)}async migrateFromString(a,t){const r=await SPD.loadFromString(a,t);r.extractData_OLD=async()=>new Promise((async(a,t)=>{try{await sodium.ready;let r={};this.data.forEach((async a=>{try{const t=sodium.crypto_secretbox_open_easy(a.data,a.nonce,this.userKey),e=zlib.inflateSync(t,{level:9}).toString("utf8");r[a.dataName]=await this.CSTI(e,a.dataType)}catch{t()}})),a(r)}catch{t()}}));const e=await r.extractData_OLD(),i=new SPD;await i.setPassKey(t);for(let a in e)await i.addData(a,e[a]);return i.saveData()}async addData(a,t){const r=await this.CITS(t);await sodium.ready;const e=Buffer.from(r[0]),i=zlib.deflateSync(e,{level:9}),s=sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES),n=sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(i,null,null,s,this.userKey),o=crypto.createHash(this.hash).update(n).digest("hex");this.data.push({dataName:a,nonce:Array.from(s),data:Array.from(n),hash:o,dataType:r[1]})}saveToFile(a){if(!(a&&"string"==typeof a&&a.trim()&&this.salt&&this.salt instanceof Uint8Array&&16===this.salt.length))throw new Error("Invalid output path or salt.");const t=JSON.stringify({data:this.data,salt:Array.from(this.salt)}),r=zlib.deflateSync(t,{level:9});fs.writeFileSync(a,r,{mode:384})}static async loadFromFile(a,t,r="sha3-512"){return new Promise((async(e,i)=>{try{a&&"string"==typeof a&&a.trim()&&t&&"string"==typeof t&&t.trim()||i(new Error("Invalid SPD path or passcode.")),await sodium.ready;const s=fs.readFileSync(a),n=zlib.inflateSync(s,{level:9}).toString("utf8"),{data:o,salt:y}=JSON.parse(n),{pqcKey:c}=await(new SPD).convertPasscodeToPQCKeySalted(t,new Uint8Array(y)),d=c.publicKey,l=new SPD;l.userKey=d,l.keyPair={publicKey:d.publicKey},l.data=o.map((a=>({dataName:a.dataName,nonce:Buffer.from(a.nonce),data:Buffer.from(a.data),hash:a.hash,dataType:a.dataType}))),l.data.forEach((a=>{crypto.createHash(r).update(Buffer.from(a.data)).digest("hex")!==a.hash&&i(new Error(`Data integrity check failed for ${a.dataName}`))})),e(l)}catch{i()}}))}async extractData(){return new Promise((async(a,t)=>{try{await sodium.ready;let r={};this.data.forEach((async a=>{try{const t=sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null,a.data,null,a.nonce,this.userKey),e=zlib.inflateSync(t,{level:9}).toString("utf8");r[a.dataName]=await this.CSTI(e,a.dataType)}catch{t()}})),a(r)}catch{t()}}))}static async derivePBK(a,t){if(!(a&&"string"==typeof a&&a.trim()&&t&&t instanceof Uint8Array&&16===t.length))throw new Error("Invalid passcode or salt.");return new Promise((async(r,e)=>{argon2.hash(a,{salt:Buffer.from(t),type:argon2.argon2id}).then((a=>{r({pbk:a,salt:t})})).catch((a=>{e(a)}))}))}saveData(){const a=JSON.stringify({data:this.data,salt:Array.from(this.salt)});return zlib.deflateSync(a,{level:9})}static async loadFromString(a,t,r="sha3-512"){return new Promise((async(e,i)=>{try{a&&"string"==typeof a&&a.trim()&&t&&"string"==typeof t&&t.trim()||i(new Error("Invalid SPD path or passcode.")),await sodium.ready;const s=Buffer.from(a,"base64"),n=zlib.inflateSync(s,{level:9}).toString("utf8"),{data:o,salt:y}=JSON.parse(n),{pqcKey:c}=await(new SPD).convertPasscodeToPQCKeySalted(t,new Uint8Array(y)),d=c.publicKey,l=new SPD;l.userKey=d,l.keyPair={publicKey:d.publicKey},l.data=o.map((a=>({dataName:a.dataName,nonce:Buffer.from(a.nonce),data:Buffer.from(a.data),hash:a.hash,dataType:a.dataType}))),l.data.forEach((a=>{crypto.createHash(r).update(Buffer.from(a.data)).digest("hex")!==a.hash&&i(new Error(`Data integrity check failed for ${a.dataName}`))})),e(l)}catch{i()}}))}async convertPasscodeToPQCKeySalted(a,t){if(!a||"string"!=typeof a||!a.trim()||a.length<8||!t||!(t instanceof Uint8Array)||16!==t.length)throw new Error("Invalid passcode or salt.");const{pbk:r}=await SPD.derivePBK(a,t);await sodium.ready;return{pqcKey:{publicKey:sodium.crypto_kx_seed_keypair(r.slice(0,sodium.crypto_kx_SEEDBYTES)).publicKey},salt:t}}async convertPasscodeToPQCKey(a){if(!a||"string"!=typeof a||!a.trim()||a.length<8)throw new Error("Invalid passcode.");const{pbk:t,salt:r}=await SPD.derivePBK(a,crypto.getRandomValues(new Uint8Array(16)));await sodium.ready;return{pqcKey:{publicKey:sodium.crypto_kx_seed_keypair(t.slice(0,sodium.crypto_kx_SEEDBYTES)).publicKey},salt:r}}async TDT(a){return{"[object Array]":"Array","[object Uint8Array]":"Uint8Array","[object Uint16Array]":"Uint16Array","[object Uint32Array]":"Uint32Array","[object BigInt64Array]":"BigInt64Array","[object BigUint64Array]":"BigUint64Array","[object Float32Array]":"Float32Array","[object Float64Array]":"Float64Array","[object Map]":"Map","[object Set]":"Set","[object Date]":"Date","[object RegExp]":"RegExp","[object Error]":"Error"}[Object.prototype.toString.call(a)]}async isNumArr(a){if("Uint8Array"===a||"Uint16Array"===a||"Uint32Array"===a||"BigInt64Array"===a||"BigUint64Array"===a||"Float32Array"===a||"Float64Array"===a)return 1}async isSWM(a){if("Map"===a||"Set"===a||"WeakMap"===a||"WeakSet"===a)return 1}async isDRE(a){if("Date"===a||"RegExp"===a||"Error"===a)return 1}async CITS(a){const t=typeof a;if("string"===t||"number"===t||"boolean"===t)return[a.toString(),t];if("object"==typeof a){const t=await this.TDT(a);return"Array"===t?[JSON.stringify(a),"Array"]:await this.isNumArr(t)?[JSON.stringify(Array.from(a)),t]:await this.isSWM(t)?[JSON.stringify([...a]),t]:await this.isDRE(t)?[a.toString(),t]:[JSON.stringify(a),typeof a]}}async CSTI(a,t){return"string"===t?a:"number"===t?parseFloat(a):"boolean"===t?"true"===a&&"false"!==a:"object"===t||"Array"===t?JSON.parse(a):"Uint8Array"===t?new Uint8Array(JSON.parse(a)):"Uint16Array"===t?new Uint16Array(JSON.parse(a)):"Uint32Array"===t?new Uint32Array(JSON.parse(a)):"BigInt64Array"===t?new BigInt64Array(JSON.parse(a)):"BigUint64Array"===t?new BigUint64Array(JSON.parse(a)):"Float32Array"===t?new Float32Array(JSON.parse(a)):"Float64Array"===t?new Float64Array(JSON.parse(a)):"Map"===t?new Map(JSON.parse(a)):"Set"===t?new Set(JSON.parse(a)):"WeakMap"===t?new WeakMap(JSON.parse(a)):"WeakSet"===t?new WeakSet(JSON.parse(a)):"Date"===t?new Date(a):"RegExp"===t?new RegExp(a):"Error"===t?new Error(a):void 0}}module.exports={SPD};