Skip to content

Instantly share code, notes, and snippets.

View kaminomisosiru's full-sized avatar

Keitaro Hashimoto kaminomisosiru

  • Tokyo Institute of Technology
  • Tokyo, Japan
View GitHub Profile
#coding:utf-8
import urllib.request
import json
# トークン発行
def get_access_token(key):
headers = {
'Ocp-Apim-Subscription-Key': key,
'Content-Length': 0
@kaminomisosiru
kaminomisosiru / language.md
Last active January 15, 2019 03:16
Available language on Microsoft Translator API
Language Code
Afrikaans af
Arabic ar
Bulgarian bg
Bangla bn
Bosnian bs
Catalan ca
Czech cs
Welsh cy
// (k,n)-threshold scheme
#include<iostream>
#include<stdio.h>
#include <random>
#include <vector>
#include <cmath>
using namespace std;
#define prime 65537
% Copyright 2018 by Keitaro Hashimoto
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/licenses/LICENSE for more details.
\mode<presentation>
@kaminomisosiru
kaminomisosiru / hatena_latex_convert.py
Last active July 6, 2017 13:20
はてなブログ用のmarkdownで$$で囲まれた\、^、_をエスケープするためのスクリプト(正しく動いているかは不明)
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
# 参考:http://d.hatena.ne.jp/greennoah/20090216/1234784592
import re
import sys
import os
# $...$で囲まれたインライン数式用の置換
def inline_replace(line):
@kaminomisosiru
kaminomisosiru / search.py
Created June 30, 2017 06:45
binary search and randomizes quick sort
# -*- coding: utf-8 -*-
import math
import random
def quick_sort(arr):
l = len(arr)
if l < 1:
return arr
@kaminomisosiru
kaminomisosiru / Algorithm.py
Last active June 27, 2017 08:36
Cryptographic Algorithm
import functools
def gcd(x, y):
'''
Euclidean Algorithm
return gcd(x, y)
'''
while y:
x, y = y, x % y
return x
@kaminomisosiru
kaminomisosiru / decrypt_RSA.py
Last active June 26, 2017 14:44
decrypt RSA (PKCS1 OAEP)
# -*- coding : utf-8 -*-
def decrypt_RSA(private_key_loc, package):
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from base64 import b64decode
key = open(private_key_loc, "r").read()
rsakey = RSA.importKey(key)
rsakey = PKCS1_OAEP.new(rsakey)
decrypted = rsakey.decrypt(b64decode(package))
# -*- coding: utf-8 -*-
'''
英文ファイルを読み込んで頻度分析を行うサンプル
'''
from collections import OrderedDict
def frequency_analysis(text):
'''
与えられたtextに対して頻度分析を行う。
結果はアルファベット順に各文字の頻度が標準出力に出力される。
@kaminomisosiru
kaminomisosiru / getMACAddress.java
Created December 2, 2016 14:53
get valid MAC Address
import java.net.NetworkInterface;
import java.util.Enumeration;
public class Main {
public static void main(String[] args) throws Exception{
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
while (nics.hasMoreElements()) {
NetworkInterface ni = nics.nextElement();
if(ni.getHardwareAddress() != null && ni.isUp() && ni.getHardwareAddress().length == 6) {