Skip to content

Instantly share code, notes, and snippets.

@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 / 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_manual.py
Last active May 27, 2021 03:14
Manually decrypt text RSA-style, given "N" and "D".
ciphertext = input("Ciphertext: ")
m = int(input("m: "))
d = int(input("D: "))
num_digits = len(str(m))
cleartext = ""
print("Decrypting (may take a while)...")
for i in range(0, len(ciphertext), num_digits):
num = int(ciphertext[i:i+num_digits])
cleartext += chr((num ** d) % m)
print()
@cbscribe
cbscribe / player.gd
Last active July 1, 2021 17:08
Player code for Godot platformer
extends KinematicBody2D
enum {IDLE, RUN, JUMP, HURT, DEAD}
var state
var anim
var new_anim
var run_speed = 150
var jump_speed = -320
var gravity = 750
var velocity = Vector2.ZERO
@cbscribe
cbscribe / snake.py
Last active July 23, 2021 23:05
Pygame programs
# https://gist.github.com/cbscribe
# To install pygame, open command prompt:
# pip install pygame
import pygame
import random
WIDTH = 800
HEIGHT = 600
@cbscribe
cbscribe / jumper.py
Last active August 7, 2021 00:04
pygame jumper
# https://gist.github.com/cbscribe
import pygame
import random
WIDTH = 800
HEIGHT = 640
FPS = 60
RUN_SPEED = 11
GRAVITY = 2
JUMP_SPEED = -31
@cbscribe
cbscribe / pygame_template.py
Last active August 11, 2021 16:35
Pygame template
import pygame
import random
WIDTH = 800
HEIGHT = 600
FPS = 60
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
@cbscribe
cbscribe / example.html
Last active September 23, 2021 15:28
HTML Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello title</title>
<link href="style.css" rel="stylesheet">
</head>
<body>
<h1>Section 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Natoque penatibus et magnis dis parturient montes nascetur. Facilisi cras fermentum odio eu. At risus viverra adipiscing at in. Ac orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt. Blandit massa enim nec dui nunc mattis enim ut. Augue ut lectus arcu bibendum at varius vel. At augue eget arcu dictum varius duis. Duis ultricies lacus sed turpis. At augue eget arcu dictum. Egestas maecenas pharetra convallis posuere morbi leo urna molestie. Pretium vulputate sapien nec sagittis aliquam. Mattis nunc sed blandit libero volutpat sed cras ornare. Sit amet mattis vulputate enim. Eget nulla facilisi etiam dignissim diam quis enim lobortis scelerisque. Urna id volutpat lacus laoreet non cura
@cbscribe
cbscribe / grade7.html
Created September 23, 2021 17:49
Mr. Bradfield's homepage example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mr. Bradfield's Classes</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!--navigation bar-->
<ul class="nav">
<li class="nav"><a href="index.html">Home</a></li>
@cbscribe
cbscribe / readability.py
Last active October 19, 2021 05:25
Readability starting code
def count_letters(text):
# TODO: Count the number of letters
num_letters = 0
print(num_letters, "letter(s)")
return num_letters
def count_words(text):
# TODO: Count the number of words
num_words = 0