Skip to content

Instantly share code, notes, and snippets.

public struct RotorBox {
public struct Rotor {
let forward: Cipher
let backward: Cipher
var position: Token
init(_ forward: @escaping Cipher, position: Token) {
self.forward = forward
public struct RotorBox {
...
public mutating func cipher(_ target: Token) -> Token {
defer {
// 関数を抜ける際に回転
rotate()
}
// rotor
let ETW_K: Cipher = { token in
switch token {
case .A: return .Q
case .B: return .W
case .C: return .E
case .D: return .R
case .E: return .T
case .F: return .Z
case .G: return .U
var enigma = Enigma(rotor0: swissK[0], rotor1: swissK[1], rotor2: swissK[2], plugboard: plugboard, key: (.A, .A, .A))
let message = "HELLOWORLD"
let message2 = "AAAAAAAAAA"
let ciphered = enigma.cipher(message)
let ciphered2 = enigma.cipher(message2)
var _enigma = Enigma(rotor0: swissK[0], rotor1: swissK[1], rotor2: swissK[2], plugboard: plugboard, key: (.A, .A, .A))
let deciphered = _enigma.cipher(ciphered)
let deciphered2 = _enigma.cipher(ciphered2)
Hello World
from keras.datasets import reuters
from keras.models import Sequential
from keras.layers import Dense
from keras.preprocessing.text import Tokenizer
(x_train, y_train), (x_test, y_test) = reuters.load_data(num_words=1000,
test_split=0.2)
tokenizer = Tokenizer(num_words=1000)
x_train = tokenizer.sequences_to_matrix(x_train, mode='binary')
import numpy as np
from keras.datasets import cifar10
from keras.utils import to_categorical
from sklearn.model_selection import train_test_split
(train_X, train_y), (test_X, test_y) = cifar10.load_data()
train_X = train_X.astype('float32') / 255
test_X = test_X.astype('float32') / 255
def le_net(shape):
from keras.models import Model
from keras.layers import Dense, Conv2D, MaxPooling2D, Flatten, Input
inputs = Input(shape=shape)
x = Conv2D(6, (5, 5), padding='same', kernel_initializer='he_normal', activation='relu')(inputs)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = Conv2D(16, (5, 5), padding='same', kernel_initializer='he_normal', activation='relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
def alex_net(shape):
from keras.models import Model
from keras.layers import Dense, Conv2D, MaxPooling2D, Flatten, Input, BatchNormalization, Dropout
from keras.regularizers import l2
weight_decay = 1e-4
inputs = Input(shape=shape)
x = Conv2D(96, (5, 5), padding='same', kernel_regularizer=l2(weight_decay), activation='relu')(inputs)
x = BatchNormalization()(x)
@KentaKudo
KentaKudo / vgg.py
Last active February 6, 2018 14:22
def vgg(shape):
from keras.models import Model
from keras.layers import Dense, Conv2D, MaxPooling2D, Flatten, Input, BatchNormalization, Dropout
from keras.regularizers import l2
weight_decay = 1e-4
inputs = Input(shape=shape)
x = Conv2D(64, (3, 3), padding='same', kernel_regularizer=l2(weight_decay), activation='relu')(inputs)
x = BatchNormalization()(x)