# Any suggestions for improvement? This is a simulation of the Enigma.

December 8 2004 at 7:56 AM

' Iain McPhee's Enigma Simulator
' written 1 December - 10 December 2004

DECLARE FUNCTION RotorI\$ (INP\$, Set)
DECLARE FUNCTION RotorII\$ (INP\$, Set)
DECLARE FUNCTION RotorIII\$ (INP\$, Set)
DECLARE FUNCTION RotorIV\$ (INP\$, Set)
DECLARE FUNCTION RotorV\$ (INP\$, Set)
DECLARE FUNCTION RotorVI\$ (INP\$, Set)
DECLARE FUNCTION RotorVII\$ (INP\$, Set)
DECLARE FUNCTION RotorVIII\$ (INP\$, Set)
DECLARE FUNCTION RotorBeta\$ (INP\$, Set)
DECLARE FUNCTION RotorGamma\$ (INP\$, Set)
DECLARE FUNCTION ReflectorB\$ (INP\$)
DECLARE FUNCTION ReflectorBDunn\$ (INP\$)
DECLARE FUNCTION ReflectorC\$ (INP\$)
DECLARE FUNCTION ReflectorCDunn\$ (INP\$)

TYPE Rotor
Sett AS INTEGER
Knock AS STRING * 2
Curr AS INTEGER
END TYPE

DIM i AS INTEGER
DIM Rotor(10) AS Rotor
DIM Stecker(26) AS STRING
DIM Letter(26) AS STRING

' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
Stecker(i) = Letter(i)
NEXT i

FOR i = 1 TO 10
Rotor(i).Curr = 0
NEXT i

CLS
PRINT "1 : Rotor I": PRINT "2 : Rotor II": PRINT "3 : Rotor III"
PRINT "4 : Rotor IV": PRINT "5 : Rotor V": PRINT "6 : Rotor VI"
PRINT "7 : Rotor VII": PRINT "8 : Rotor VIII": PRINT "9 : Beta Rotor"
PRINT "10 : Gamma Rotor : NOTE! Gamma and Beta Rotors can only be in left slot"
INPUT "Enter the number for the rightmost rotor "; RinPI
INPUT "Enter the number for the middle rotor "; RinPII
INPUT "Enter the number for the leftmost rotor "; RinPIII

CLS
PRINT "The ring settings (Use letters, not numbers):"
INPUT "Rightmost Rotor "; RightR\$
INPUT "Middle Rotor "; MiddleR\$
INPUT "Leftmost Rotor "; LeftR\$
PRINT "Core Setting, letter"
INPUT "Rightmost Rotor "; RightC\$
INPUT "Middle Rotor "; MiddleC\$
INPUT "Leftmost Rotor "; LeftC\$
FOR i = 1 TO 26
IF RightC\$ = Letter(i) THEN RC = i
IF MiddleC\$ = Letter(i) THEN MC = i
IF LeftC\$ = Letter(i) THEN LC = i
IF RightR\$ = Letter(i) THEN RR = i
IF MiddleR\$ = Letter(i) THEN MR = i
IF LeftR\$ = Letter(i) THEN LR = i
NEXT i
' The letter displayed in the window is calculated with ring setting plus core setting
RotSet1 = RC + RR
RotSet2 = MC + MR
RotSet3 = LR + LC
' This is the reflector selection:
PRINT "1B : 2B Dunn : 3C : 4C Dunn"
INPUT "Enter the number of the corresponding reflector "; Reflector
' Plugboard vars- A\$ temp storage Y, Z, temp storage Stecker(Array)
PRINT "How many stecker(plug)board connections?"
INPUT NUM

CLS
IF NUM > 0 THEN
FOR i = 1 TO NUM
FOR Z = 1 TO 13
PRINT Z; " "; Letter(Z); " : ";
NEXT Z
PRINT
FOR Z = 14 TO 26
PRINT Z; " "; Letter(Z); " : ";
NEXT Z
INPUT "Enter the number of the first plug "; Z
INPUT "Enter the number of the second plug "; Y
A\$ = Stecker(Z)
Stecker(Z) = Stecker(Y)
Stecker(Y) = A\$
NEXT i
END IF

' What Rotor is it
FOR i = 1 TO 10
IF RinPI = i THEN
Rotor(i).Curr = 1
Rotor(i).Sett = RotSet1
END IF
IF RinPII = i THEN
Rotor(i).Curr = 2
Rotor(i).Sett = RotSet2
END IF
IF RinPIII = i THEN
Rotor(i).Curr = 3
Rotor(i).Sett = RotSet3
END IF
NEXT i

' The Main Part of the code
DO UNTIL FINP\$ = "!"
CLS
FOR i = 1 TO 10
IF Rotor(i).Curr = 1 THEN R\$ = Letter(Rotor(i).Sett)
IF Rotor(i).Curr = 2 THEN M\$ = Letter(Rotor(i).Sett)
IF Rotor(i).Curr = 3 THEN L\$ = Letter(Rotor(i).Sett)
NEXT i
PRINT "In the 'Windows:'"
PRINT L\$; " "; M\$; " "; R\$
PRINT "At the prompt, enter the letter to be encoded, '!' to exit this bit"
INPUT INP\$
INP\$ = UCASE\$(INP\$)
FINP\$ = INP\$
Reverse = 0
FOR i = 1 TO 26
IF INP\$ = Letter(i) THEN
INP\$ = Stecker(i)
END IF
NEXT i
' The Rotor in the far right position
IF Rotor(1).Curr = 1 THEN
Set = Rotor(1).Sett + 1
Rotor(1).Sett = Set
A\$ = RotorI\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "R" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(2).Curr = 1 THEN
Set = Rotor(2).Sett + 1
Rotor(2).Sett = Set
A\$ = RotorII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "F" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(3).Curr = 1 THEN
Set = Rotor(3).Sett + 1
Rotor(3).Sett = Set
A\$ = RotorIII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "W" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(4).Curr = 1 THEN
Set = Rotor(4).Sett + 1
Rotor(4).Sett = Set
A\$ = RotorIV\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "K" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(5).Curr = 1 THEN
Set = Rotor(5).Sett + 1
Rotor(5).Sett = Set
A\$ = RotorV\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(6).Curr = 1 THEN
Set = Rotor(6).Sett + 1
Rotor(6).Sett = Set
A\$ = RotorVI\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" OR A\$ = "N" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(7).Curr = 1 THEN
Set = Rotor(7).Sett + 1
Rotor(7).Sett = Set
A\$ = RotorVII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" OR A\$ = "N" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(8).Curr = 1 THEN
Set = Rotor(8).Sett + 1
Rotor(8).Sett = Set
A\$ = RotorVIII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" OR A\$ = "N" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
' The rotor in the second position
IF Rotor(1).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(1).Sett + 1
Rotor(1).Sett = Set
END IF
A\$ = RotorI\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "R" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(2).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(2).Sett + 1
Rotor(2).Sett = Set
END IF
A\$ = RotorII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "F" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(3).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(3).Sett + 1
Rotor(3).Sett = Set
END IF
A\$ = RotorIII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "W" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(4).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(4).Sett + 1
Rotor(4).Sett = Set
END IF
A\$ = RotorIV\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "K" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(5).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(5).Sett + 1
Rotor(5).Sett = Set
END IF
A\$ = RotorV\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(6).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(6).Sett + 1
Rotor(6).Sett = Set
END IF
A\$ = RotorVI\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" OR A\$ = "N" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(7).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(7).Sett + 1
Rotor(7).Sett = Set
END IF
A\$ = RotorVII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" OR A\$ = "N" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
IF Rotor(8).Curr = 2 THEN
IF KnockNext = 1 THEN
Set = Rotor(8).Sett + 1
Rotor(8).Sett = Set
END IF
A\$ = RotorVIII\$(INP\$, Set)
INP\$ = A\$
IF A\$ = "A" OR A\$ = "N" THEN
KnockNext = 1
ELSE
KnockNext = 0
END IF
END IF
' The leftmost Rotor
IF Rotor(1).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(1).Sett + 1
Rotor(1).Sett = Set
END IF
A\$ = RotorI\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(2).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(2).Sett + 1
Rotor(2).Sett = Set
END IF
A\$ = RotorII\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(3).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(3).Sett + 1
Rotor(3).Sett = Set
END IF
A\$ = RotorIII\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(4).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(4).Sett + 1
Rotor(4).Sett = Set
END IF
A\$ = RotorIV\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(5).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(5).Sett + 1
Rotor(5).Sett = Set
END IF
A\$ = RotorV\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(6).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(6).Sett + 1
Rotor(6).Sett = Set
END IF
A\$ = RotorVI\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(7).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(7).Sett + 1
Rotor(7).Sett = Set
END IF
A\$ = RotorVII\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(8).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(8).Sett + 1
Rotor(8).Sett = Set
END IF
A\$ = RotorVIII\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(9).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(9).Sett + 1
Rotor(9).Sett = Set
END IF
A\$ = RotorBeta\$(INP\$, Set)
INP\$ = A\$
END IF
IF Rotor(10).Curr = 3 THEN
IF KnockNext = 1 THEN
Set = Rotor(10).Sett + 1
Rotor(10).Sett = Set
END IF
A\$ = RotorGamma\$(INP\$, Set)
INP\$ = A\$
END IF
' END OF THE IF-THEN STATEMENTS
' Reflectors
IF Reflector = 1 THEN INP\$ = ReflectorB\$(INP\$)
IF Reflector = 2 THEN INP\$ = ReflectorBDunn\$(INP\$)
IF Reflector = 3 THEN INP\$ = ReflectorC\$(INP\$)
IF Reflector = 4 THEN INP\$ = ReflectorCDunn\$(INP\$)
Reverse = 1
' The leftmost Rotor
IF Rotor(1).Curr = 3 THEN
A\$ = RotorI\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(2).Curr = 3 THEN
A\$ = RotorII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(3).Curr = 3 THEN
A\$ = RotorIII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(4).Curr = 3 THEN
A\$ = RotorIV\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(5).Curr = 3 THEN
A\$ = RotorV\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(6).Curr = 3 THEN
A\$ = RotorVI\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(7).Curr = 3 THEN
A\$ = RotorVII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(8).Curr = 3 THEN
A\$ = RotorVIII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(9).Curr = 3 THEN
A\$ = RotorBeta\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(10).Curr = 3 THEN
A\$ = RotorGamma\$(INP\$, -Set)
INP\$ = A\$
END IF
' The rotor in the second position
IF Rotor(1).Curr = 2 THEN
A\$ = RotorI\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(2).Curr = 2 THEN
A\$ = RotorII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(3).Curr = 2 THEN
A\$ = RotorIII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(4).Curr = 2 THEN
A\$ = RotorIV\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(5).Curr = 2 THEN
A\$ = RotorV\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(6).Curr = 2 THEN
A\$ = RotorVI\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(7).Curr = 2 THEN
A\$ = RotorVII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(8).Curr = 2 THEN
A\$ = RotorVIII\$(INP\$, -Set)
INP\$ = A\$
END IF
' The Rotor in the far right position
IF Rotor(1).Curr = 1 THEN
A\$ = RotorI\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(2).Curr = 1 THEN
A\$ = RotorII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(3).Curr = 1 THEN
A\$ = RotorIII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(4).Curr = 1 THEN
A\$ = RotorIV\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(5).Curr = 1 THEN
A\$ = RotorV\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(6).Curr = 1 THEN
A\$ = RotorVI\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(7).Curr = 1 THEN
A\$ = RotorVII\$(INP\$, -Set)
INP\$ = A\$
END IF
IF Rotor(8).Curr = 1 THEN
A\$ = RotorVIII\$(INP\$, -Set)
INP\$ = A\$
END IF
' End of the IF-THEN STATEMENTS
FOR i = 1 TO 26
IF INP\$ = Letter(i) THEN
INP\$ = Stecker(i)
END IF
NEXT i
PRINT "The input was: "; FINP\$
PRINT "The output is: "; INP\$
PRINT
PRINT "Press any key to continue."
SLEEP
LOOP
SYSTEM

FUNCTION ReflectorB\$ (INP\$)
' ReflectorB Input is INP\$ THIS IS A FUNCTION!!!
DIM Letter(26) AS STRING
DIM Reflector(26) AS STRING
DIM i AS INTEGER
' The Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Reflector
Reflector(1) = "Y": Reflector(2) = "R": Reflector(3) = "U": Reflector(4) = "H"
Reflector(5) = "Q": Reflector(6) = "S": Reflector(7) = "L": Reflector(8) = "D"
Reflector(9) = "P": Reflector(10) = "X": Reflector(11) = "N": Reflector(12) = "G"
Reflector(13) = "O": Reflector(14) = "K": Reflector(15) = "M": Reflector(16) = "I"
Reflector(17) = "E": Reflector(18) = "B": Reflector(19) = "F": Reflector(20) = "Z"
Reflector(21) = "C": Reflector(22) = "W": Reflector(23) = "V": Reflector(24) = "J"
Reflector(25) = "A": Reflector(26) = "T"
FOR i = 1 TO 26
IF INP\$ = Letter\$(i) THEN
OUT\$ = Reflector(i)
i = 27
END IF
NEXT i
ReflectorB\$ = OUT\$
END FUNCTION

FUNCTION ReflectorBDunn\$ (INP\$)
' ReflectorBDunn Input is INP\$ THIS IS A FUNCTION!!!
DIM Letter(26) AS STRING
DIM Reflector(26) AS STRING
DIM i AS INTEGER
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Reflector
Reflector(1) = "E": Reflector(2) = "N": Reflector(3) = "K": Reflector(4) = "Q"
Reflector(5) = "A": Reflector(6) = "U": Reflector(7) = "Y": Reflector(8) = "W"
Reflector(9) = "J": Reflector(10) = "I": Reflector(11) = "C": Reflector(12) = "O"
Reflector(13) = "P": Reflector(14) = "B": Reflector(15) = "L": Reflector(16) = "M"
Reflector(17) = "D": Reflector(18) = "X": Reflector(19) = "Z": Reflector(20) = "V"
Reflector(21) = "F": Reflector(22) = "T": Reflector(23) = "H": Reflector(24) = "R"
Reflector(25) = "G": Reflector(26) = "S"
FOR i = 1 TO 26
IF INP\$ = Letter\$(i) THEN
OUT\$ = Reflector(i)
i = 27
END IF
NEXT i
ReflectorBDunn\$ = OUT\$
END FUNCTION

FUNCTION ReflectorC\$ (INP\$)
' ReflectorC Input is INP\$ THIS IS A FUNCTION!!!
DIM Letter(26) AS STRING
DIM Reflector(26) AS STRING
DIM i AS INTEGER
' The Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Reflector
Reflector(1) = "F": Reflector(2) = "V": Reflector(3) = "P": Reflector(4) = "J"
Reflector(5) = "I": Reflector(6) = "A": Reflector(7) = "O": Reflector(8) = "Y"
Reflector(9) = "E": Reflector(10) = "D": Reflector(11) = "R": Reflector(12) = "Z"
Reflector(13) = "X": Reflector(14) = "N": Reflector(15) = "G": Reflector(16) = "C"
Reflector(17) = "T": Reflector(18) = "K": Reflector(19) = "U": Reflector(20) = "Q"
Reflector(21) = "S": Reflector(22) = "B": Reflector(23) = "N": Reflector(24) = "M"
Reflector(25) = "H": Reflector(26) = "L"
FOR i = 1 TO 26
IF INP\$ = Letter\$(i) THEN
OUT\$ = Reflector(i)
i = 27
END IF
NEXT i
ReflectorC\$ = OUT\$
END FUNCTION

FUNCTION ReflectorCDunn\$ (INP\$)
' ReflectorCDunn Input is INP\$ THIS IS A FUNCTION!!!
DIM Letter(26) AS STRING
DIM Reflector(26) AS STRING
DIM i AS INTEGER
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Reflector
Reflector(1) = "R": Reflector(2) = "D": Reflector(3) = "O": Reflector(4) = "B"
Reflector(5) = "J": Reflector(6) = "N": Reflector(7) = "T": Reflector(8) = "K"
Reflector(9) = "V": Reflector(10) = "E": Reflector(11) = "H": Reflector(12) = "M"
Reflector(13) = "L": Reflector(14) = "F": Reflector(15) = "C": Reflector(16) = "W"
Reflector(17) = "Z": Reflector(18) = "R": Reflector(19) = "X": Reflector(20) = "G"
Reflector(21) = "Y": Reflector(22) = "I": Reflector(23) = "P": Reflector(24) = "S"
Reflector(25) = "U": Reflector(26) = "Q"
FOR i = 1 TO 26
IF INP\$ = Letter\$(i) THEN
OUT\$ = Reflector(i)
i = 27
END IF
NEXT i
ReflectorCDunn\$ = OUT\$
END FUNCTION

FUNCTION RotorBeta\$ (INP\$, Set)
' RotorBeta Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "L": Rotor(2) = "E": Rotor(3) = "Y": Rotor(4) = "J"
Rotor(5) = "V": Rotor(6) = "C": Rotor(7) = "N": Rotor(8) = "I"
Rotor(9) = "X": Rotor(10) = "W": Rotor(11) = "P": Rotor(12) = "B"
Rotor(13) = "Q": Rotor(14) = "M": Rotor(15) = "D": Rotor(16) = "R"
Rotor(17) = "T": Rotor(18) = "A": Rotor(19) = "K": Rotor(20) = "Z"
Rotor(21) = "G": Rotor(22) = "F": Rotor(23) = "U": Rotor(24) = "H"
Rotor(25) = "O": Rotor(26) = "S"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
NEXT i
RotorBeta\$ = OUT\$
END FUNCTION

FUNCTION RotorGamma\$ (INP\$, Set)
' RotorGamma Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "F": Rotor(2) = "S": Rotor(3) = "O": Rotor(4) = "K"
Rotor(5) = "A": Rotor(6) = "N": Rotor(7) = "U": Rotor(8) = "E"
Rotor(9) = "R": Rotor(10) = "H": Rotor(11) = "M": Rotor(12) = "B"
Rotor(13) = "T": Rotor(14) = "I": Rotor(15) = "Y": Rotor(16) = "C"
Rotor(17) = "W": Rotor(18) = "L": Rotor(19) = "Q": Rotor(20) = "P"
Rotor(21) = "Z": Rotor(22) = "X": Rotor(23) = "V": Rotor(24) = "G"
Rotor(25) = "J": Rotor(26) = "D"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
NEXT i
RotorGamma\$ = OUT\$
END FUNCTION

FUNCTION RotorI\$ (INP\$, Set)
' RotorI Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "E": Rotor(2) = "K": Rotor(3) = "M": Rotor(4) = "F"
Rotor(5) = "L": Rotor(6) = "G": Rotor(7) = "D": Rotor(8) = "Q"
Rotor(9) = "V": Rotor(10) = "Z": Rotor(11) = "N": Rotor(12) = "T"
Rotor(13) = "O": Rotor(14) = "W": Rotor(15) = "Y": Rotor(16) = "H"
Rotor(17) = "X": Rotor(18) = "U": Rotor(19) = "S": Rotor(20) = "P"
Rotor(21) = "A": Rotor(22) = "I": Rotor(23) = "B": Rotor(24) = "R"
Rotor(25) = "C": Rotor(26) = "J"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorI\$ = OUT\$ 'Change RotorI to the proper rotor
END FUNCTION

FUNCTION RotorII\$ (INP\$, Set)
' RotorII Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "A": Rotor(2) = "J": Rotor(3) = "D": Rotor(4) = "K"
Rotor(5) = "S": Rotor(6) = "I": Rotor(7) = "R": Rotor(8) = "U"
Rotor(9) = "X": Rotor(10) = "B": Rotor(11) = "L": Rotor(12) = "H"
Rotor(13) = "W": Rotor(14) = "T": Rotor(15) = "M": Rotor(16) = "C"
Rotor(17) = "Q": Rotor(18) = "G": Rotor(19) = "Z": Rotor(20) = "N"
Rotor(21) = "P": Rotor(22) = "Y": Rotor(23) = "F": Rotor(24) = "V"
Rotor(25) = "O": Rotor(26) = "E"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorII\$ = OUT\$
END FUNCTION

FUNCTION RotorIII\$ (INP\$, Set)
' RotorIII Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "B": Rotor(2) = "D": Rotor(3) = "F": Rotor(4) = "H"
Rotor(5) = "J": Rotor(6) = "L": Rotor(7) = "C": Rotor(8) = "P"
Rotor(9) = "R": Rotor(10) = "T": Rotor(11) = "X": Rotor(12) = "V"
Rotor(13) = "Z": Rotor(14) = "N": Rotor(15) = "Y": Rotor(16) = "E"
Rotor(17) = "I": Rotor(18) = "W": Rotor(19) = "G": Rotor(20) = "A"
Rotor(21) = "K": Rotor(22) = "M": Rotor(23) = "U": Rotor(24) = "S"
Rotor(25) = "Q": Rotor(26) = "O"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorIII\$ = OUT\$
END FUNCTION

FUNCTION RotorIV\$ (INP\$, Set)
' RotorIV Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "E": Rotor(2) = "S": Rotor(3) = "O": Rotor(4) = "V"
Rotor(5) = "P": Rotor(6) = "Z": Rotor(7) = "J": Rotor(8) = "A"
Rotor(9) = "Y": Rotor(10) = "Q": Rotor(11) = "U": Rotor(12) = "I"
Rotor(13) = "R": Rotor(14) = "H": Rotor(15) = "X": Rotor(16) = "L"
Rotor(17) = "N": Rotor(18) = "F": Rotor(19) = "T": Rotor(20) = "G"
Rotor(21) = "K": Rotor(22) = "D": Rotor(23) = "C": Rotor(24) = "M"
Rotor(25) = "W": Rotor(26) = "B"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorIV\$ = OUT\$
END FUNCTION

FUNCTION RotorV\$ (INP\$, Set)
' RotorV Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "V": Rotor(2) = "Z": Rotor(3) = "B": Rotor(4) = "R"
Rotor(5) = "G": Rotor(6) = "I": Rotor(7) = "T": Rotor(8) = "Y"
Rotor(9) = "U": Rotor(10) = "P": Rotor(11) = "S": Rotor(12) = "D"
Rotor(13) = "N": Rotor(14) = "H": Rotor(15) = "L": Rotor(16) = "X"
Rotor(17) = "A": Rotor(18) = "W": Rotor(19) = "M": Rotor(20) = "J"
Rotor(21) = "Q": Rotor(22) = "O": Rotor(23) = "F": Rotor(24) = "E"
Rotor(25) = "C": Rotor(26) = "K"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorV\$ = OUT\$
END FUNCTION

FUNCTION RotorVI\$ (INP\$, Set)
' RotorVI Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "J": Rotor(2) = "P": Rotor(3) = "G": Rotor(4) = "V"
Rotor(5) = "O": Rotor(6) = "U": Rotor(7) = "M": Rotor(8) = "F"
Rotor(9) = "Y": Rotor(10) = "Q": Rotor(11) = "B": Rotor(12) = "E"
Rotor(13) = "N": Rotor(14) = "H": Rotor(15) = "Z": Rotor(16) = "R"
Rotor(17) = "D": Rotor(18) = "K": Rotor(19) = "A": Rotor(20) = "S"
Rotor(21) = "X": Rotor(22) = "L": Rotor(23) = "I": Rotor(24) = "C"
Rotor(25) = "T": Rotor(26) = "W"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorVI\$ = OUT\$
END FUNCTION

FUNCTION RotorVII\$ (INP\$, Set)
' RotorVII Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "N": Rotor(2) = "Z": Rotor(3) = "J": Rotor(4) = "H"
Rotor(5) = "G": Rotor(6) = "R": Rotor(7) = "C": Rotor(8) = "X"
Rotor(9) = "M": Rotor(10) = "Y": Rotor(11) = "S": Rotor(12) = "W"
Rotor(13) = "B": Rotor(14) = "O": Rotor(15) = "U": Rotor(16) = "F"
Rotor(17) = "A": Rotor(18) = "I": Rotor(19) = "V": Rotor(20) = "L"
Rotor(21) = "P": Rotor(22) = "E": Rotor(23) = "K": Rotor(24) = "Q"
Rotor(25) = "D": Rotor(26) = "T"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorVII\$ = OUT\$
END FUNCTION

FUNCTION RotorVIII\$ (INP\$, Set)
' RotorVIII Inputs = INP\$, Set
DIM Rotor(26) AS STRING
IF Set < 0 THEN
Set = Set * -1
Reverse = 1
ELSE Reverse = 0
END IF
' Rotor array is to be set according to rotor used
DIM RotorPosistion(26) AS INTEGER
' Used in calculating the setting
DIM NewSet, Position, i AS INTEGER
DIM Letter(26) AS STRING
' For the Alphabet
FOR i = 1 TO 26
Letter(i) = CHR\$(64 + i)
NEXT i
' The Rotor Substitutions
Rotor(1) = "F": Rotor(2) = "K": Rotor(3) = "Q": Rotor(4) = "H"
Rotor(5) = "T": Rotor(6) = "L": Rotor(7) = "X": Rotor(8) = "O"
Rotor(9) = "C": Rotor(10) = "B": Rotor(11) = "J": Rotor(12) = "S"
Rotor(13) = "P": Rotor(14) = "D": Rotor(15) = "Z": Rotor(16) = "R"
Rotor(17) = "A": Rotor(18) = "M": Rotor(19) = "E": Rotor(20) = "W"
Rotor(21) = "N": Rotor(22) = "I": Rotor(23) = "U": Rotor(24) = "Y"
Rotor(25) = "G": Rotor(26) = "V"
' The following calculates the rotor position
FOR i = 1 TO 26
IF Set + i > 26 THEN
NewSet = Set + i - 26
ELSE
NewSet = Set + i
END IF
RotorPosistion(i) = NewSet
NEXT i
' Now for substituting
FOR i = 1 TO 26
IF Reverse = 0 THEN
IF INP\$ = Letter(i) THEN
OUT\$ = Rotor(RotorPosistion(i))
END IF
ELSE
IF INP\$ = Rotor(RotorPosistion(i)) THEN
OUT\$ = Letter(i)
END IF
END IF
NEXT i
RotorVIII\$ = OUT\$
END FUNCTION

 This message has been edited by iorr5t on Dec 15, 2004 11:29 AM

 Respond to this message
 Response Title Author and Date My suggestion, Iain, is to try it out yourself :-( (View Thread) Mac on Dec 9 ACK! I posted the wrong version! Iain on Dec 10 Mac, Please replace the above program with this one Iain on Dec 15 Some suggestions, Iain (View Thread) Mac on Dec 15 Some explanation Iain McPhee on Dec 15 A bug Mac on Dec 15 I am working on those* Iain on Dec 16 Another bug Mac on Dec 15 when you want a gui for this mennonite on May 17 The new version of Enigma (View Thread) Iain McPhee on Dec 19 Some help is needed Iain McPhee on Dec 19 Check this out, Iain Mac on Dec 20 Some help for Iain Mac on Dec 20 To Decrypt Iain McPhee on Dec 20 Right. OK, Iain, here is a real useful suggestion Mac on Dec 20 I give up, Iain Mac on Dec 21 Enigma prblem figured out (View Thread) Iain on Apr 27 Iain, where in the world have you been? Mac on Apr 27 *I meant a QB GUI, ie all ASCII. (View Thread) Iain on Nov 2 Hi, Iain Mac on Nov 3 A little late in replying Iain on Mar 17 ROFL, Iain Mac on Mar 17 Simulation of a German WWII Cryptographic Center using Enigma Mac on Mar 17