Skip to content

Instantly share code, notes, and snippets.

View yvki's full-sized avatar
:bowtie:
#今天珉天再加叶班#

v yvki

:bowtie:
#今天珉天再加叶班#
View GitHub Profile
@yvki
yvki / SampleFunc2.py
Created May 4, 2024 06:33
LSB Matching method 🔄️ in Python for Steganography
import sys, cv2, random
import numpy as np
def extract():
J=cv2.imread('image1.png')
f=open('output_payload.txt', 'w+', errors="ignore")
idx=0
bitidx=0
bitval=0
@yvki
yvki / SampleFunc1.py
Created May 3, 2024 07:50
LSB Replacement method 🔄️ in Python for Steganography
# Import required computer vision and array-based math libraries
import cv2, numpy as np
# Function to convert any type of data into binary
def to_bin(data):
"""Used to convert payload and pixel values to binary in payload hiding and extracting phase"""
if isinstance(data, str):
return ''.join([ format(ord(i), "08b") for i in data ])
elif isinstance(data, bytes) or isinstance(data, np.ndarray):
return [ format(ord(i), "08b") for i in data ]
@yvki
yvki / captchaBypass.py
Created May 3, 2024 07:28
Python script (used with Burp Suite) for Juice Shop 🧃 3-Stars Challenge #4 Captcha Bypass ⛔
import requests
import json
# Spam 10 negative feedback forms
for x in range(0,10):
# GET captcha id and answer
r = requests.get("http://127.0.0.1:3000/rest/captcha/")
data = r.json()
captcha_id = data['captchaId']
captcha_answer = data['answer']
# Create form parameters
@yvki
yvki / cleanTextNBPipeline.py
Created May 1, 2024 08:53
Naive Bayes Text Classification Pipeline ⚙️ for Sentiment Analysis (or similar) tasks 📩
import pandas as pd
import numpy as np
import string
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import accuracy_score, classification_report
@yvki
yvki / pysparkCheats.py
Created April 24, 2024 07:27
PySpark Data Handling Cheatsheet ⚙️
# 1. Data Loading
# 1.1 Load from CSV file
df = spark.read.csv('filename.csv', header=True, inferSchema=True)
# 1.2 Load from JDBC (Java Database)
df = spark.read.format("jdbc").options(url="jdbc_url", dbtable="tablename").load()
# 1.3 Load from text file
df = spark.read.text('filename.txt')
# 2. Data Inspection
# 2.1 Display top rows
@yvki
yvki / logregPipeline.py
Created April 22, 2024 05:59
Sample Spaceship Titanic 🚀 scikit-learn logistic regression pipeline with GridSearch hyperparameter tuning ⚙️
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
from sklearn.feature_selection import SelectPercentile, f_classif
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LogisticRegression
pipe_lgrg = make_pipeline(
PolynomialFeatures(include_bias=False),
StandardScaler(),
SelectPercentile(score_func=f_classif),
LogisticRegression(max_iter=2000, random_state=22)
@yvki
yvki / cosineSimilarityRec.py
Created April 18, 2024 07:49
Sample Movie 📽️ Recommendation System 🔢 using Cosine Similarity ⚙️
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
# Sample ratings matrix for 5 movies by 5 users
ratings = np.array([
# [Movie 1, Movie 2, Movie 3, Movie 4, Movie 5]
[5, 3, 4, 4, 0], # User 1
[3, 1, 2, 3, 3], # User 2
[4, 3, 4, 3, 5], # User 3
[3, 3, 1, 5, 4], # User 4
@yvki
yvki / predClassifiers.py
Created April 15, 2024 07:53
Predicting Spaceship Titanic 🚀 survival rates with different GridSearch classifier types ⚙️
# 1. Extreme Gradient Boosting (comparable to LightGBM)
from xgboost import XGBClassifier
from sklearn.model_selection import GridSearchCV
xgb = XGBClassifier(random_state=22)
param_grid_xgb = {
'n_estimators': [300],
'max_depth': [4],
'learning_rate': [0.1],
'subsample': [1.0],
'colsample_bytree': [0.8]
@yvki
yvki / machlearnFunc.py
Created April 14, 2024 05:25
Simple implementation of Activation, MSE Loss, Propagation Functions ⚙️
# 1. Algorithm to create depiction of Sigmoid class activation function
class Sigmoid:
def __init__(self):
return
def forward(self, x):
sigmoid_x = 1 / (1 + np.exp(-x))
return sigmoid_x
def derivative(self, z):
sigmoid_z = self.forward(z)
sigmoid_derivative_z = sigmoid_z * (1 - sigmoid_z)
@yvki
yvki / perceptronCreation.py
Created April 14, 2024 05:07
Simple algorithmic implementation of Neural Network Architecture ⚙️
# 1. Algorithm to normalize the training and testing data
def normalize_data(X_train, X_test):
mean_X_train = np.mean(X_train, axis=0)
std_X_train = np.std(X_train, axis=0)
X_train = np.divide((X_train - mean_X_train), std_X_train)
X_test = np.divide((X_test - mean_X_train), std_X_train)
return X_train, X_test
X_train, X_test = normalize_data(X_train, X_test)
print("First three lines of X_train:", X_train[:5])
print("\nFirst three lines of X_test:", X_test[:5])