Created
November 30, 2023 22:41
-
-
Save MrDwarf7/ca9bbfa77a6c3791debd4e326cb4ae2c to your computer and use it in GitHub Desktop.
ConvolutedScriptsTwo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use serde::{Deserialize, Serialize}; | |
use serde_json::{json, Value}; | |
#[derive(Serialize, Deserialize, Debug)] | |
struct ComplexData { | |
data: Vec<u32>, | |
message: String, | |
} | |
fn obscure_serialization(data: &ComplexData) -> Value { | |
serde_json::to_value(data).unwrap_or(json!({"error": "Serialization failed"})) | |
} | |
fn main() { | |
let data = ComplexData { | |
data: vec![1, 2, 3, 4, 5], | |
message: String::from("Serde in Rust"), | |
}; | |
let serialized = obscure_serialization(&data); | |
println!("Serialized data: {}", serialized); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel, validator | |
import itertools | |
class ObfuscatedDataModel(BaseModel): | |
data: list[int] | |
obscure_transformation: str | |
@validator('data', pre=True, always=True) | |
def convoluted_processing(cls, v, values, **kwargs): | |
transformation = values.get('obscure_transformation', '') | |
if transformation == 'quadratic': | |
return [x**2 for x in v] | |
elif transformation == 'factorial': | |
factorial = lambda x: x * factorial(x-1) if x > 1 else 1 | |
return list(map(factorial, v)) | |
return list(itertools.accumulate(v, lambda x, y: x * y)) | |
def complex_analysis(self): | |
return sum(self.data) % len(self.data) | |
# Usage | |
model = ObfuscatedDataModel(data=[1, 2, 3, 4], obscure_transformation='factorial') | |
print(model.complex_analysis()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
type ConfusingObject = { [key: string]: any }; | |
const processData = (data: ConfusingObject): ConfusingObject => { | |
const deepClonedData = _.cloneDeep(data); | |
_.forEach(deepClonedData, (value, key) => { | |
if (_.isArray(value)) { | |
deepClonedData[key] = _.chain(value).map(_.toString).sort().value(); | |
} else if (_.isPlainObject(value)) { | |
deepClonedData[key] = processData(value); | |
} else { | |
deepClonedData[key] = _.isNumber(value) ? _.multiply(value, _.random(1, 10)) : value; | |
} | |
}); | |
return _.zipObject(_.shuffle(Object.keys(deepClonedData)), _.values(deepClonedData)); | |
}; | |
const exampleData = { a: [2, 1, 3], b: { c: 5, d: 7 }, e: "text" }; | |
console.log(processData(exampleData)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment