Skip to content

Instantly share code, notes, and snippets.

@sambaiz
sambaiz / ai.pl
Last active August 29, 2015 13:55
perlではない
%?- talk(hello, X). で会話できる
talk(hello, hello).
talk(こんにちは, こんにちは).
talk(ばか, あほ).
talk(今日はいい天気ですね, そうですね).
talk(あなたはだれ?, 人工知能です).
#シーザー暗号
#ruby caesar.rb piyopiyo -2
#ngwmngwm
def caesar_cipher(str, shift)
str.split(//).each {|c| print (c.ord + shift.to_i).chr}
end
caesar_cipher(ARGV[0], ARGV[1])
@sambaiz
sambaiz / angou.scala
Created February 13, 2014 19:02
abcdefghijklm <-> nopqrstuvwxyzで文字を置換しただけの暗号@CodeIQ
scala> val angou = "fhaal naq jvaql"
angou: String = fhaal naq jvaql
scala> angou.map({s => if(s < 'a' || s > 'z') s else if(s <= 'm') (s + 'n' - 'a').toChar else (s - 'n' + 'a').toChar})
res43: String = sunny and windy
# -*- coding: utf-8 -*-
import numpy as np
import pylab as plt
import copy
def jacobi_or_seidel(x, a, b, use_jacobi = True):
cpx = copy.copy(x) if use_jacobi else x
for i in range(x.size):
cpx[i] = b[i]
@sambaiz
sambaiz / lettercount.rb
Last active August 29, 2015 13:56
英文テキストファイルの各アルファベットの数を出力して割合をグラフで表示する
require "gnuplot"
# (gem install gnuplot)
# (brew install gnuplot)
INPUT_DATA = ARGV[0] || raise("input file name is not given")
OUTPUT_DATA = ARGV[1] || "output.txt"
OUTPUT_GRAPH = ARGV[2] || "output.eps"
n = 0
@sambaiz
sambaiz / hakuhoudou1.rb
Created February 21, 2014 11:23
URLデコード(utf-8)@某ES-1
require 'uri'
buf = ""
File::open(ARGV[0]) {|file|
file.each {|line|
line = buf + line.strip
while line.length >= 9 do
print URI.decode(line[0..8])
line = line[9..line.length-1]
end
buf = line
@sambaiz
sambaiz / hakuhoudou2.rb
Created February 23, 2014 15:37
RSA暗号方式の復号@某ES-2
require 'uri'
require 'prime'
# RSA暗号
# 公開鍵(E, N)
E = 47 #適当な正整数
N = 323 #素数p * 素数q
D_RANGE = 1000 #秘密鍵の推定最大値(一応ループ回避)
def decryption(x, d)
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
/**
* Created by sambaiz on 2014/03/06.
*/
@sambaiz
sambaiz / brute\force_mini.rb
Created April 24, 2014 02:48
てきとう
max_length = 5
password = 'poor'
chars = ('a'..'z').to_a
searches = Array.new
searches << ""
length = 0
while true
new_searches = Array.new
length += 1
@sambaiz
sambaiz / memo.kt
Created April 26, 2014 16:58
Kotlin's ? and !!
val hello : String? = "hello"
var bye : String? = "bye"
//(hello or bye).length is error (need ? or !!)
hello!!
hello.length //ok
bye!!
//bye.length is error (need ? or !!)
bye?.length // if bye == null, return null