Rename Enigma.swift -> Machine.swift
This commit is contained in:
parent
bb1ba6a1fc
commit
6a2e4fd44e
2 changed files with 53 additions and 4 deletions
|
@ -7,7 +7,7 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
C04D337F1B5B3F6100E2888E /* Enigma.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04D337E1B5B3F6100E2888E /* Enigma.swift */; };
|
C04D337F1B5B3F6100E2888E /* Machine.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04D337E1B5B3F6100E2888E /* Machine.swift */; };
|
||||||
C0DA3A911B5AACB300D8D68E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DA3A901B5AACB300D8D68E /* AppDelegate.swift */; };
|
C0DA3A911B5AACB300D8D68E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DA3A901B5AACB300D8D68E /* AppDelegate.swift */; };
|
||||||
C0DA3A931B5AACB300D8D68E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DA3A921B5AACB300D8D68E /* ViewController.swift */; };
|
C0DA3A931B5AACB300D8D68E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DA3A921B5AACB300D8D68E /* ViewController.swift */; };
|
||||||
C0DA3A961B5AACB300D8D68E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C0DA3A941B5AACB300D8D68E /* Main.storyboard */; };
|
C0DA3A961B5AACB300D8D68E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C0DA3A941B5AACB300D8D68E /* Main.storyboard */; };
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
/* End PBXContainerItemProxy section */
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
C04D337E1B5B3F6100E2888E /* Enigma.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enigma.swift; sourceTree = "<group>"; };
|
C04D337E1B5B3F6100E2888E /* Machine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Machine.swift; sourceTree = "<group>"; };
|
||||||
C0DA3A8D1B5AACB300D8D68E /* Enigma.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Enigma.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
C0DA3A8D1B5AACB300D8D68E /* Enigma.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Enigma.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
C0DA3A901B5AACB300D8D68E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
C0DA3A901B5AACB300D8D68E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
C0DA3A921B5AACB300D8D68E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
C0DA3A921B5AACB300D8D68E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
C0DA3A991B5AACB300D8D68E /* LaunchScreen.storyboard */,
|
C0DA3A991B5AACB300D8D68E /* LaunchScreen.storyboard */,
|
||||||
C0DA3A9C1B5AACB300D8D68E /* Info.plist */,
|
C0DA3A9C1B5AACB300D8D68E /* Info.plist */,
|
||||||
C0DA3ABE1B5AB49200D8D68E /* Components.swift */,
|
C0DA3ABE1B5AB49200D8D68E /* Components.swift */,
|
||||||
C04D337E1B5B3F6100E2888E /* Enigma.swift */,
|
C04D337E1B5B3F6100E2888E /* Machine.swift */,
|
||||||
);
|
);
|
||||||
path = Enigma;
|
path = Enigma;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -261,7 +261,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
C04D337F1B5B3F6100E2888E /* Enigma.swift in Sources */,
|
C04D337F1B5B3F6100E2888E /* Machine.swift in Sources */,
|
||||||
C0DA3ABF1B5AB49200D8D68E /* Components.swift in Sources */,
|
C0DA3ABF1B5AB49200D8D68E /* Components.swift in Sources */,
|
||||||
C0DA3A931B5AACB300D8D68E /* ViewController.swift in Sources */,
|
C0DA3A931B5AACB300D8D68E /* ViewController.swift in Sources */,
|
||||||
C0DA3A911B5AACB300D8D68E /* AppDelegate.swift in Sources */,
|
C0DA3A911B5AACB300D8D68E /* AppDelegate.swift in Sources */,
|
||||||
|
|
49
Enigma/Machine.swift
Normal file
49
Enigma/Machine.swift
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
//
|
||||||
|
// Machine.swift
|
||||||
|
// Enigma
|
||||||
|
//
|
||||||
|
// Created by Eryn Wells on 7/18/15.
|
||||||
|
// Copyright © 2015 Eryn Wells. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
|
class Machine {
|
||||||
|
let rotors: [Rotor]
|
||||||
|
let reflector: Reflector
|
||||||
|
let plugboard: Plugboard
|
||||||
|
|
||||||
|
init(rotors: [Rotor], reflector: Reflector, plugboard: Plugboard) {
|
||||||
|
self.rotors = rotors
|
||||||
|
self.reflector = reflector
|
||||||
|
self.plugboard = plugboard
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(c: Character) throws -> Character {
|
||||||
|
var output = c
|
||||||
|
output = try plugboard.encode(output)
|
||||||
|
for rotor in rotors {
|
||||||
|
output = try rotor.encode(output)
|
||||||
|
}
|
||||||
|
output = try reflector.encode(output)
|
||||||
|
for rotor in rotors.reverse() {
|
||||||
|
output = try rotor.encode(output)
|
||||||
|
}
|
||||||
|
output = try plugboard.encode(output)
|
||||||
|
advanceRotors()
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(string: String) throws -> String {
|
||||||
|
var output = ""
|
||||||
|
for character in string.characters {
|
||||||
|
output += String(try encode(character))
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
private func advanceRotors() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue