Skip to content

Instantly share code, notes, and snippets.

View AdamGold's full-sized avatar
🌏
Trust the process

Adam Goldschmidt AdamGold

🌏
Trust the process
  • Israel
View GitHub Profile
def __init__(self, size=10):
self.entries = [None for _ in range(size * 2)]
self.size = size
self.actual_size = size * 2
self.filled_entries = 0
def __setitem__(self, key: str, value: Any) -> int:
"""allow insertion of items with object[key] = value"""
if self.filled_entries == self.size:
# no more room
def __setitem__(self, key: str, value: Any) -> int:
"""allow insertion of items with object[key] = value"""
entry = Entry(key, value)
index = entry.hash % self.actual_size
self.entries[index] = entry
return index
def __getitem__(self, key: str) -> Entry:
"""subscript method - object[key]
use hashing function to find the index"""
entry = Entry(key)
index = entry.hash % self.actual_size
found = self.entries[index]
if found == None:
raise KeyError
return found
{
"definitions": {
"Device": {
"type": "object"
},
"Feedback": {
"properties": {
"feedback": {
"type": "integer"
}
{
"definitions": {
"<script>alert(1)</script>": {
"type": "object"
},
"Feedback": {
"properties": {
"feedback": {
"type": "integer"
}

Fix for encode_message()

The XOR key should be 42, not 7.

Corrected function:

def encode_message(message: str) -> str:
    return "".join(chr(ord(c) ^ 42) for c in message)