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 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 |
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 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 ] |
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 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 |
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 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 |
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
# 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 |
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 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) |
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 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 |
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
# 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] |
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
# 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) |
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
# 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]) |
NewerOlder