Skip to content

Instantly share code, notes, and snippets.

@tty007
tty007 / rsa.rb
Created October 6, 2018 05:23
Rubyで作るRSA暗号
class RSA
attr_accessor :p, :q
def initialize(text)
@text = text
end
def setting_keys(p, q)
@p = p
@q = q
@tty007
tty007 / main.js
Created October 2, 2018 02:52
Blockchain(add a nonce ver.) with JavaScript
const SHA256 = require("crypto-js/sha256");
class Block {
constructor(index, timestamp, data, previousHash = '') {
this.index = index;
this.previousHash = previousHash;
this.timestamp = timestamp;
this.data = data;
this.hash = this.calculateHash();
this.nonce = 0;
@tty007
tty007 / main.js
Last active October 1, 2018 12:59
Blockchain with JavaScript
const SHA256 = require("crypto-js/sha256");
class Block {
constructor(index, timestamp, data, previousHash = '') {
this.index = index;
this.previousHash = previousHash;
this.timestamp = timestamp;
this.data = data;
this.hash = this.calculateHash();
}
@tty007
tty007 / rgb.py
Created June 19, 2018 08:10
rgbから色コード・色コードからrgbを求めるRubyプログラム
def to_hex(r, g, b)
[r, g, b].inject('#') do |hex, n|
hex + n.to_s(16).rjust(2, '0')
end
end
def to_ints(hex)
hex.scan(/\w\w/).map(&:hex)
end