This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import hmac | |
import hashlib | |
import struct | |
import base64 | |
from typing import bytes as Bytes, Tuple, List | |
import time | |
import secrets | |
class SimpleBcrypt: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
from typing import List, bytes as Bytes | |
class SHA256: | |
""" | |
A complete implementation of SHA-256 hash algorithm. | |
This implementation is for educational purposes and to understand | |
the inner workings of SHA-256. For production use, always use | |
the hashlib library which is optimized and thoroughly tested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import math | |
class SimpleMD5: | |
def __init__(self): | |
# MD5 constants | |
self.h = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476] | |
# Pre-computed sine values for MD5 rounds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventBus: | |
def __init__(self): | |
# A dictionary to store event types and their listener functions | |
# key: event_type (string), value: list of listener functions | |
self.listeners = {} | |
def on(self, event_type, listener): | |
"""Registers a listener for a specific event type.""" | |
if event_type not in self.listeners: | |
self.listeners[event_type] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Broker: | |
def __init__(self): | |
# A dictionary to store topics and their subscribers | |
# key: topic (string), value: set of subscriber callback functions | |
self.subscribers = {} | |
def subscribe(self, topic, callback): | |
"""Adds a new subscriber to a topic.""" | |
# If the topic doesn't exist, create an empty set for it | |
if topic not in self.subscribers: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from typing import Optional, Any, List, Tuple | |
class SkipListNode: | |
"""Node in the skip list containing key-value pair and forward pointers""" | |
def __init__(self, key: Any, value: Any, level: int): | |
self.key = key | |
self.value = value |