Skip to content

Instantly share code, notes, and snippets.

View frodo821's full-sized avatar
:octocat:
Working from home

frodo821

:octocat:
Working from home
View GitHub Profile
@frodo821
frodo821 / syspro_week_8_problem_2_server.c
Created July 31, 2022 00:29
システムプログラミング 第8週 練習問題802 のコードを供養
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <arpa/inet.h>
@frodo821
frodo821 / keccak256.nim
Created March 27, 2022 13:36
keccak256 implementation in Nim
## keccak256 (sha3-256) implementation in Nim
## for further details of this process: https://keccak.team/keccak_specs_summary.html
type
HashWords {.union.} = object
words: array[25, uint64]
bytes: array[200, uint8]
HashState* = ref object
hw: HashWords
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@frodo821
frodo821 / ElGamal.ipynb
Last active October 5, 2021 16:16
ElGamal暗号を実装してみた
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@frodo821
frodo821 / magic.ipynb
Last active October 4, 2021 00:56
魔法円をスキャンするやつ(簡易版) 簡易版なので方向補正、歪み補正のコードは含まれていません
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@frodo821
frodo821 / snowflake.py
Created September 22, 2021 15:14
snowflake identifier generator implementation by python
from time import time_ns
from threading import Lock
class SnowflakeGenerator:
def __init__(self, instance_id, epoch=-1):
self.instance_id = (instance_id&1023)<<12
self.epoch = (time_ns()//1000 & 2199023255551) if epoch == -1 else epoch
self.seq = 0
self.last_timestamp = 0
self.lock = Lock()
from math import radians, sin, cos
import matplotlib.pyplot as plt
import numpy as np
from dataclasses import dataclass
def length(vec: np.array):
return vec.dot(vec) ** 0.5
@frodo821
frodo821 / vigenere_cipher.py
Created June 4, 2021 13:40
ヴィジュネル暗号(Vigenère cipher)
from itertools import cycle
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
chrs = cycle('ZABCDEFGHIJKLMNOPQRSTUVWXY')
table = {l: {a[i-1]: c for c, i in zip(chrs, range(26)) if i != 0} for l in a}
def encode(message: str, key: str) -> str:
return ''.join(
c if u else c.lower() for c, u in (
(table[k.upper()].get(m.upper(), m.upper()), m.isupper()) for m, k in zip(message, cycle(key))
)
#define W_PASSWORD "wifi-password"
#define W_SSID "wifi-ssid"
#define HOST "0.0.0.0"
#define PORT 80
#include <M5Stack.h>
#undef min
#include "shs_network_time.h"
#include "simplehttpserver.h"
WiFiServer server(PORT);
@frodo821
frodo821 / blockchain.py
Created April 22, 2021 02:40
A minimal test implementation of blockchain (proof of works). p2p based protocols are not implemented.
from hashlib import sha256
from datetime import datetime
from json import dumps
class Block:
def __init__(self, nonce, data, prevHash=None, difficulty=20):
self.nonce = nonce
self.data = data
self.timestamp = datetime.now().timestamp()
self.prevHash = prevHash