Skip to content

Instantly share code, notes, and snippets.

View vhxs's full-sized avatar
🤔
contemplating

Vikram Saraph vhxs

🤔
contemplating
View GitHub Profile

This writeup outlines a solution for Locking Mechanism and also my thought process in solving it. This was my first time doing a CTF and my very first solve ever.

We're given a Dockerized Rust application, but I decided to build the code directly on my machine since I already had Cargo installed and up to date. I'm not that well-versed in Rust yet (I solved a few Advent of Code problems in it), but I know enough to poke around. The first thing I tried was to just cargo build and cargo run the application and see what happens. It didn't halt, so upon looking at the code it looked like it was expecting an input of comma-separated integers.

In the file I noticed that there was a list of 104 integers, particularly this:

#include <Arduino.h>
struct BCD {
int eights;
int fours;
int twos;
int ones;
};
struct BCD decimal_to_BCD(int value) {
@vhxs
vhxs / mst.py
Created December 26, 2023 01:07
Testing edge order is all that matters to make MSTs
import random
import networkx as nx
def random_graph() -> nx.Graph:
num_nodes = 20
probability = 0.2
return nx.erdos_renyi_graph(num_nodes, probability)
@vhxs
vhxs / t5_translate.py
Created September 12, 2023 01:03
T5 translation example
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("t5-base")
model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")
example_input = "This sentence is false"
input_ids = tokenizer("translate English to German: "+example_input, return_tensors="pt").input_ids
outputs = model.generate(input_ids)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
@vhxs
vhxs / bluesky_post.py
Created September 10, 2023 18:08
Minimal example of using Bluesky's API to post
import requests
import os
from datetime import datetime, timezone
# Fetch the current time
# Using a trailing "Z" is preferred over the "+00:00" format
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
# Required fields that each post must include
post = {
@vhxs
vhxs / fine_tune_resnet18_on_dogs_and_cats.py
Created August 13, 2023 23:17
ChatGPT-suggested fine-tuning example
import os
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision.models as models
import torchvision.transforms as transforms
import torchvision.datasets as datasets
# Load pre-trained ResNet-18
model = models.resnet18(pretrained=True)
@vhxs
vhxs / move_triangles.py
Created August 12, 2023 19:12
ChatGPT-generated code to animate a coupla triangles
import pygame
# Initialize Pygame
pygame.init()
# Set up display
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pygame Glide Transformation Animation")
@vhxs
vhxs / langchain_arxiv.py
Created August 12, 2023 17:35
Using LangChain to ask about one of my papers.
from langchain.document_loaders import OnlinePDFLoader
from langchain.indexes import VectorstoreIndexCreator
loader = OnlinePDFLoader("https://arxiv.org/pdf/1606.06353.pdf")
documents = loader.load()
index = VectorstoreIndexCreator().from_documents(documents)
print(index.query("What are the main results of this paper?"))
@vhxs
vhxs / langchain_mastodon.py
Last active August 12, 2023 17:30
Using LangChain's question answering capability to ask questions about what I post on Mastodon
from langchain.document_loaders import MastodonTootsLoader
from langchain.indexes import VectorstoreIndexCreator
from langchain.vectorstores.utils import filter_complex_metadata
loader = MastodonTootsLoader(mastodon_accounts=["@vsaraph@mathstodon.xyz"], number_toots=300)
documents = loader.load()
documents = filter_complex_metadata(documents)
index = VectorstoreIndexCreator().from_documents(documents)
print(index.query("What kinds of interests does this user have?"))
@vhxs
vhxs / cpu_vs_gpu_torch.py
Created August 6, 2023 21:27
GPU vectorization via PyTorch
import numpy as np
import torch
from datetime import datetime
if __name__ == '__main__':
num_dims = 3
dim = 1024
for _ in range(10):