Skip to content

Instantly share code, notes, and snippets.

View Sam-Belliveau's full-sized avatar

Sam Belliveau Sam-Belliveau

  • Cornell University
  • Ithaca, NY
View GitHub Profile
from Crypto.Cipher import AES # Encryption
import hashlib # Turn user password into key
# Get key based on user password
def generate_key(password, key_len, salt=b'steven_is_really_lame', iterations=262144):
# Use hmac to generate key based on user password
hash = hashlib.pbkdf2_hmac('sha256', bytes(password), bytes(salt), iterations, key_len)
return bytes(hash)
# Default nonce for every
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#define BUFFER_SIZE 0x10000
int write_getline(FILE* file)
{
// buffer
static char buffer[BUFFER_SIZE];
@Sam-Belliveau
Sam-Belliveau / crc.hpp
Last active September 17, 2024 20:54
CRC16, CRC32, and CRC64 in constexpr C++14
/**
* Copyright 2019 Sam Robert Belliveau
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
@Sam-Belliveau
Sam-Belliveau / eval.hpp
Last active October 10, 2021 20:02
A Infix Notation Evaluator
/**
* MIT License
*
* Copyright (c) Sep 2019, Samuel Robert Belliveau
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@Sam-Belliveau
Sam-Belliveau / ChaCha.hpp
Last active September 26, 2021 20:22
Fast, Secure, Robust, and Documented Implementation of ChaCha for C++. Compatible with the <random> header file and interfaces
/**
* MIT License
*
* Copyright (c) 2021, Samuel Robert Belliveau
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@Sam-Belliveau
Sam-Belliveau / RawBytes.hpp
Last active August 12, 2019 23:26
Constexpr library for manipulating the rawbytes of a type while avoiding UB
#ifndef SAM_BELLIVEAU_RAW_BYTE_CONTAINTER
#define SAM_BELLIVEAU_RAW_BYTE_CONTAINTER 1
#include <cstdint> // Size Types
#include <cstring> // std::memcpy
#include <exception> // std::overflow
#include <initializer_list> // std::initializer_list
#include <iterator> // Iterator stuff
template<class InputType>
@Sam-Belliveau
Sam-Belliveau / ImgSteg.py
Created July 24, 2019 20:46
Reference Code for Image Steg.
from PIL import Image
# Store letter in a pixel of the image
def StoreLetter(pixel, letter):
# Make a copy of the image
r, g, b = pixel
# Clear out the bottom bits
r &= 0b11111000
g &= 0b11111100