Skip to content

Instantly share code, notes, and snippets.

@cbscribe
cbscribe / aes.py
Created May 25, 2021 03:14
Python AES encrypt/decrypt
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
from Crypto.Util.Padding import pad, unpad
import base64
key = input("Key: ").encode()
def encrypt():
iv = get_random_bytes(AES.block_size)
@cbscribe
cbscribe / rsa.py
Last active February 3, 2022 05:51
Encrypt/Decrypt with RSA
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import base64
def encrypt():
keyfile = input("Public key file: ")
with open(keyfile, "r") as file:
data = file.read()
public_key = RSA.import_key(data)
cleartext = input("Cleartext: ").encode()
@cbscribe
cbscribe / rsa_sign.py
Last active February 9, 2022 02:20
Python RSA tools
# Run `pip install pycryptodome` to install Crypto library
from Crypto.PublicKey import RSA
from Crypto.Signature import pss
from Crypto.Hash import SHA256
import base64
def sign():
with open("private.key", "r") as file:
data = file.read()
private_key = RSA.import_key(data)
@cbscribe
cbscribe / find_d.py
Created April 28, 2021 21:22
Find a value for D (RSA algorithm)
# This program finds a value for D in the RSA algorithm
# Given values for A and E
A = int(input("A: "))
E = int(input("E: "))
# Start at E so D will be bigger
n = E
while True:
n += 1
@cbscribe
cbscribe / pacman.c
Created April 20, 2021 03:46
Arduino+LCD Pacman example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte pacman1[] = {
B01110,
B11111,
B11011,
B11111,
B11100,
@cbscribe
cbscribe / bar.c
Created April 19, 2021 21:48
Arduino+LCD Bar Graph Example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
}
@cbscribe
cbscribe / add.html
Last active April 16, 2021 19:06
Flask Todo list app
{% extends "layout.html" %}
{% block body %}
<form action="/add" method="post">
<input type="text" name="task">
<input type="submit">
</form>
{% endblock %}
@cbscribe
cbscribe / lcd_example.c
Created April 15, 2021 16:25
Example Arduino + LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
// Set the size of the display
lcd.begin(16, 2);
// Print out some text
lcd.print("This is a really long line.");
@cbscribe
cbscribe / analog_meter.c
Last active April 12, 2021 21:33
Arduino NeoPIxel Examples
#include <Adafruit_NeoPixel.h>
# define PIN 2
# define NUM_PIXELS 6
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIN);
void setup()
{
pixels.begin();
}
@cbscribe
cbscribe / blockchain.py
Created April 9, 2021 18:20
Blockchain example
import hashlib
import json
from time import time
class Blockchain:
def __init__(self):
self.chain = []
self.pending_transactions = []
self.new_block(previous_hash="1234", proof=100)