Skip to content

Instantly share code, notes, and snippets.

View taravancil's full-sized avatar

Tara Vancil taravancil

View GitHub Profile
@taravancil
taravancil / README.md
Last active August 23, 2021 23:17
A bash script for downloading CDN assets for a Glitch project

Scrape Glitch Assets

Problem

When using glitch.com's Download Project tool (Tools > Import and Export > Download Project), the resulting archive does not include project assets that were uploaded to the Glitch CDN.

Solution

The download does however include a metadata file .glitch-assets that lists the project's CDN files.

This script downloads the files listed in a .glitch-assets file and writes them to a local directory.

@taravancil
taravancil / clojure-links.md
Created December 11, 2016 16:22
A collection of links for learning Clojure
@taravancil
taravancil / majority.py
Last active April 30, 2018 04:32
Find the majority element in an array
def get_majority(A, k):
"""
Return the majority element in an array. O(n) time.
This is an implementation of Moore's voting algorithm.
"""
maj_index = 0
count = 1
for i in range (1, len(A-1)):
# If the current element is equal to the index of the majority element, increment count
@taravancil
taravancil / common1.py
Last active October 4, 2016 23:03
Approaches for finding the most common integer in an array.
# Constraints: an array of size n of integers in the range 0 to k-1, where k is a positive integer and k <= n
test = [0, 1, 1, 1, 3, 17, 5, 3, 2, 1, 9] # k = 10, n = 11
get_common(test, 10)
def get_common(A, k):
"""Return the most popular integer in an array. O(n) time, O(k) space."""
# Create a lookup array with length k to track the occurrence of each possible member.
# O(k) space
lookup = [0] * k
@taravancil
taravancil / quicksort.js
Created September 30, 2016 13:51
An implementation of quicksort
'use strict'
const nums = [3, 0, 2, 5, 1, 3, 0]
quicksort(nums, 0, nums.length - 1)
console.log(nums)
const chars = ['z', 'a', 'u', 'f', 'f', 'A']
quicksort(chars, 0, chars.length - 1)
console.log(chars)
@taravancil
taravancil / insertion-sort.js
Last active September 29, 2016 15:36
An implementation of insertion sort
// Average case O(n^2)
function insertionSort (arr) {
// Begin at position 1, because we need to compare the element at
// that position to the previous element
for (let i = 1; i < arr.length; i++) {
let j = i
// If the prior element is greater than the current element (arr[j]), swap
while (j > 0 && arr[j-1] > arr[j]) {
// Storing the tmp variable requires O(1) memory space
function processData(input) {
const lines = input.split('\n')
// Discard the first line
lines.shift()
for (line of lines) {
// Split line into array of chars
countMinimumDeletions(line.split(''))
}
@taravancil
taravancil / one-pointer.js
Last active September 28, 2016 01:35
Two solutions for finding pairs of numbers in a list with a given difference. See https://www.hackerrank.com/challenges/pairs for more test cases.
function onePointer (input) {
const lines = input.split('\n')
const k = Number(lines[0].split(' ')[1])
let nums = lines[1].split(' ').map(x => Number(x))
let count = 0
// Sort the numbers in order to limit the number of required comparisons
nums.sort((a, b) => a - b)
// For each element, calculate the difference between it and subsequent elements up to

Decrypting a Ciphertext With a Padding Oracle

See the code in its entirety here.

This code exploits a "padding oracle" in order to decrypt a ciphertext encrypted with AES-128 in CBC mode.

The Padding Oracle

The oracle decrypts a ciphertext and then determines if the resulting plaintext has valid PKCS#7 padding. This may seem innocent, but because an attacker can provide arbitrary text to the oracle, it can actually provide sufficient information to decrypt a ciphertext without knowledge of the key.

Decryption in CBC Mode

Each block of ciphertext is first decrypted with the key, then XORed with the preceding block of ciphertext (except the first block, which is XORed with the initialization vector) to produce the corresponding plaintext block.