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

My suggestion, Iain, is to try it out yourself :-(

December 9 2004, 6:59 AM
 After a lot of work trying to fix your strange character set so quote and hyphen were correct, I still bombed immediately. TYPE Rotor Sett AS INTEGER Knock AS STRING Curr AS INTEGER END TYPE You can't have a variable length string in a TYPE. Anyway, Rotor(i).Knock or the equivalent is not used anywhere in the program. So I just deleted that line to get past that error. But the I bombed on IF A\$ = "A" OR IF A\$ = "N" THEN There is no such thing as 'OR IF'! Of course, I could change this line to IF (A\$ = "A") OR (A\$ = "N") THEN and continue, but instead, I lost interest and am suggesting that you should get the program to run in QBasic. Then save in an ASCII file and post that file. Mac
 Respond to this message
Iain

ACK! I posted the wrong version!

December 10 2004, 4:49 AM
 I didnae mean to do that. I posted one that I messed up. I shall post the correct one.
 Respond to this message
Iain

Mac, Please replace the above program with this one

December 15 2004, 4:44 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 END 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
 Respond to this message

Some suggestions, Iain

December 15 2004, 12:23 PM
 Good Project! I was a bit frustrated trying to find input that would work, not being an Enigma expert. Please supply a sample set of goodies to enter. That is, please supply responses to all those prompts. I finally got it to run but may have broke something because whenever I entered a letter to be encoded, the same result came out. AAAA should encode to VMEW or something, I would think. Anyway, I was frustrated by all the prompting for the letters and substituted the stuff below, removing the SLEEP at the bottom. Mac CLS ' The Main Part of the code DO   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   locate 1,1,1   PRINT "In the 'Windows:'"   PRINT L\$; " "; M\$; " "; R\$   PRINT   PRINT "Enter the letter to be encoded"   PRINT "(Press ESC when finished)"   PRINT   DO: INP\$ = INKEY\$: LOOP WHILE INP\$ = ""   IF INP\$ = CHR\$(27) THEN EXIT DO   INP\$ = UCASE\$(INP\$)   FINP\$ = INP\$   PRINT INP\$
 Respond to this message
Iain McPhee
R

Some explanation

December 15 2004, 3:54 PM
 I have also removed the sleep statement, for it caused a wee problem: If enter was pressed, the rotors advanced as if though a letter was encoded This could cause problems with decoding. There are a several more bugs that I have discovered, but I am working on them The stecker plugs, Ring Setting, and the Core Setting for each rotor form the 'Key' There where 10 rotors on the various versions of the Military Enigma, the beta and gamma rotors (along with the B and C Dünn Reflectors) for the navy only. The Beta and Gamma rotors could also only go in the far left position, for they had no 'knocking', which was the advance ment of the next rotor to the left at a certain letter. I ententionally made it so that the program does not record the encoded message. The real thing didn't. What I would like is for everyone on the forums to test the thing to shreds. Once the bugs are worked out, I can try to do a gui. (This will be hard for me, so if someone else could do it, I would be thankful) Cheers mate!+++++++++++++++++++++++++++++ ACK! Where's me tea and towel? CALL THE ARMY! CALL THE RAF! CALL THE NAVY! THIS IS NO DRILL! I CANNAE FIND, oh there's me towel and tea. Alert over
 Respond to this message

A bug

December 15 2004, 4:51 PM

In the following code, on entering the 27th input character, I get "subscript out of range":

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

Using the following input
2 4 6
m a r
p q h
2
4
8 11
7 13
4 12
17 3

And entering 27 A's
A is a G
A is a T
A is a Z
....

Mac

 This message has been edited by Mac36 on Dec 15, 2004 4:56 PM

 Respond to this message
Iain

I am working on those*

December 16 2004, 4:38 AM
 *
 Respond to this message

Another bug

December 15 2004, 4:55 PM

Side note = Check this out
http://www.w1tp.com/enigma/EnigmaSim.zip

I ran it but was unable to figure out what I was doing.

Anyway, in the following code, I get "subscript out of range" if I enter the same settings as given in the other post, but instead use uppercase letters on inpus.

Suggested fix: Use LCASE\$ when getting those letters.

Mac

' The Main Part of the code
DO
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

 This message has been edited by Mac36 on Dec 15, 2004 6:09 PM

 Respond to this message
mennonite

when you want a gui for this

May 17 2005, 4:25 PM
 let me know all the variables you want put in and sent to the program by the gui and draw (a) picture(s) ** of how you'd like it to look on the screen and any extra feautres you'd like, describe them in detail :) feel free to include the urls of graphics ** you'd like to simulate. results may vary. *unless you'd really rather i figure that out for you **acceptable formats: bmp, gif, jpg, png, tif, jpeg2, pcx
 Respond to this message
Iain McPhee
R

The new version of Enigma

December 19 2004, 7:20 PM
 ' 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\$ RightR\$ = UCASE\$(RightR\$) INPUT "Middle Rotor "; MiddleR\$ MiddleR\$ = UCASE\$(MiddleR\$) INPUT "Leftmost Rotor "; LeftR\$ LeftR\$ = UCASE\$(LeftR\$) PRINT "Core Setting, letter" INPUT "Rightmost Rotor "; RightC\$ RightC\$ = UCASE\$(RightC\$) INPUT "Middle Rotor "; MiddleC\$ MiddleC\$ = UCASE\$(MiddleC\$) INPUT "Leftmost Rotor "; LeftC\$ LeftC\$ = UCASE\$(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." 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 +++++++++++++++++++++++++++++ Useing small words and layman's terms confuses me
 Respond to this message
Iain McPhee
R

Some help is needed

December 19 2004, 7:51 PM
 1 I donnae understand why there is an error in this bit: 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 'This line right here, provided for the 'reciprocal bit of the original enigma OUT\$ = Letter(i) END IF What happens is that the RotorPosition array equals a number > 26 It should be taken care of by this: IF Set + i > 26 THEN NewSet = Set + i - 26 'This line, it should subtract 26, thus giving 1 ELSE NewSet = Set + i END IF RotorPosistion(i) = NewSet I feel that the answer is obvious, but I cannae see it 2 Could someone please make a gui, here is a link to what the original looked like: http://webhome.idirect.com/~jproc/crypto/enigma.html 3 Mac, I tried your suggested code, but it didnae work. 4 Also, I must add a warning not to press enter without a letter to input+++++++++++++++++++++++++++++ Useing small words and layman's terms confuses me
 Respond to this message

Check this out, Iain

December 20 2004, 7:14 AM
 TYPE Rotor Sett AS INTEGER Knock AS STRING * 2 Curr AS INTEGER END TYPE CONST Debugging = -1: 'Note: Comment this line out when not debugging 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 IF Debugging THEN   RinPI = 2:  RinPII = 4:  RinPIII = 6 ELSE   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 END IF IF Debugging THEN   RightR\$ = "m": MiddleR\$ = "a": LeftR\$ = "r" ELSE   CLS   PRINT "The ring settings (Use letters, not numbers):"   INPUT "Rightmost Rotor "; RightR\$   INPUT "Middle Rotor "; MiddleR\$   INPUT "Leftmost Rotor "; LeftR\$ END IF RightR\$ = UCASE\$(RightR\$) MiddleR\$ = UCASE\$(MiddleR\$) LeftR\$ = UCASE\$(LeftR\$) IF Debugging THEN   RightC\$ = "p": MiddleC\$ = "q": LeftC\$ = "h" ELSE   PRINT "Core Setting, letter"   INPUT "Rightmost Rotor "; RightC\$   INPUT "Middle Rotor "; MiddleC\$   INPUT "Leftmost Rotor "; LeftC\$ END IF RightC\$ = UCASE\$(RightC\$) MiddleC\$ = UCASE\$(MiddleC\$) LeftC\$ = UCASE\$(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: IF RotSet1 > 26 THEN RotSet1 = RotSet1 - 26 RotSet2 = MC + MR: IF RotSet2 > 26 THEN RotSet2 = RotSet2 - 26 RotSet3 = LR + LC: IF RotSet3 > 26 THEN RotSet3 = RotSet3 - 26 ' This is the reflector selection: IF Debugging THEN   Reflector = 2 ELSE   PRINT "1B : 2B Dunn : 3C : 4C Dunn"   INPUT "Enter the number of the corresponding reflector "; Reflector END IF ' Plugboard vars- A\$ temp storage Y, Z, temp storage Stecker(Array) IF Debugging THEN   NUM = 4 ELSE   PRINT "How many stecker(plug)board connections?"   INPUT NUM END IF 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     IF Debugging THEN       READ Z       READ Y       DATA 8,11,7,13,4,12,17,3     ELSE       INPUT "Enter the number of the first plug "; Z       INPUT "Enter the number of the second plug "; Y     END IF     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 CLS DO   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   LOCATE 5, 20:  PRINT "In the 'Windows' ";   COLOR 0, 7: PRINT L\$; M\$; R\$   COLOR 7, 0: PRINT : PRINT   PRINT "Enter the letter to be encoded"   PRINT "(Just press Enter when finished)"   PRINT   LOCATE , , 1   DO: INP\$ = INKEY\$: LOOP WHILE INP\$ = ""   IF INP\$ = CHR\$(13) THEN EXIT DO   INP\$ = UCASE\$(INP\$)   PRINT INP\$: PRINT   GOSUB ProcessIMP   PRINT INP\$ LOOP CLS SYSTEM ProcessIMP: FINP\$ = INP\$ Reverse = 0 FOR i = 1 TO 26   IF INP\$ = Letter(i) THEN     INP\$ = Stecker(i)   END IF NEXT i GOSUB StepRotors ' 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 RETURN StepRotors: ' The Rotor in the far right position IF Rotor(1).Curr = 1 THEN   Set = Rotor(1).Sett + 1: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26   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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     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: IF Set > 26 THEN Set = Set - 26     Rotor(10).Sett = Set   END IF   A\$ = RotorGamma\$(INP\$, Set)   INP\$ = A\$ END IF RETURN 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
 Respond to this message

Some help for Iain

December 20 2004, 7:23 AM
 > I feel that the answer is obvious, but I cannae see it There were a zillion more places where you add 1. I patched the emulator and posted it (title: "Check this out, Iain"). Scan through that for all "> 26" and see where I added them. > Make you a Gui Not me! I suck at graphics. But I think the one found at http://www.w1tp.com/enigma/EnigmaSim.zip is quite good. However, I personally prefer QBasic style printing like the program currently does. > Tried my suggested code but it didnae work OK, I inserted it into the version I posted. > Don't press enter I fixed it actually so Enter terminates input. ====================================== Note that the version I posted contains a constant, "Debugging". Just comment it out. It was there to allow easier testing. By the way, how do you unencrypt? I didn't see an option to choose encryption or decryption. Mac
 Respond to this message
Iain McPhee
R

To Decrypt

December 20 2004, 8:46 AM
 Set it EXACTLY the same way as for encrypting, and just type the message back in, one letter at a time+++++++++++++++++++++++++++++ Useing small words and layman's terms confuses me
 Respond to this message

Right. OK, Iain, here is a real useful suggestion

December 20 2004, 2:10 PM
 I looked on the internet and found many brilliant emulations of the Enigma. No way you can compete with them! http://www.codesandciphers.org.uk/enigma/index.htm http://www.ellsbury.com/enigma4.htm plus the emulator I already told you about. BUT they all have one thing in common - A bogus interface where you have to laborously enter stecker connections, etc. You can make something that is new and useful! Something like this (I don't know enough about the Enigma to be specific) 1) Request machine type (army? navy? whatever) 2) Enter line from codebook: (It looks like this:) IV III VI M F Q DN GR IS KC QX TM PV HY FW BJ Now you have everything you need except the per-message stuff: 3) Enter 3 letter key: VSP 4) Enter message THISI SASAM PLEME SSAGE That's all. No blinky lights, no stecker wiring bogus pain-in-the-ass time-wasting stuff. Just what I said. Now THAT would be a useful addition to the library of Enigma stuff, not another stupid emulation that requires you to laborously do all that manual work! There are PLENTY of those and they are beautiful. But not useful. You have a chance to make something worthwhile. Mac Here it is again, as envisioned by me: (Remember, I am weak on what I am talking about here. I depend on you reading between the lines and doing something correctly) Enigma Simulation by Iain ====== ========== == ==== Enter model: B-short, B-long, C-short, C-long: B-long Enter codebook line: II IV VI 23 12 18 DN GR IS KC QX TM PV HY FW BJ Enter message key: JRF Message? This is a message for you to read Result: MXPUF QQFSL JRMLV BOXMF OWMJL M Another? Y Enter message key: HUM Message? JOWBE LJOBP CSXPB JEJAO Result: Herei syour answe rtome Another? N Goodbye!
 Respond to this message

I give up, Iain

December 21 2004, 6:43 PM

With Reflector B (large, for 5 rotors)
Using II, V, I (left to right)
Ring Settings 13-M 21-U 8-H
And with 2 Steckers: AG BF (1-7 2-6)

If I set the rotors to F Q M (from left to right)
and enter "ababa"
I get "thdei" with the Rotors resting at F R R.

I get those results on two reputable simulations:

http://frode.home.cern.ch/frode/crypto/simula/DR/EnigmaSim.zip

I do not get them from you and I can't find the bug.

Bye!

Mac

 This message has been edited by Mac36 on Dec 21, 2004 9:11 PM

 Respond to this message
Iain

Enigma prblem figured out

April 27 2005, 11:34 AM
 Apparantely, on some architectures it works perfectly, on others it acts in an odd manour. On a linux box running a dos emulator, it would do odd things when the H stecker was used. On the same computer running DOS, it ran perfectly. +++++++++++ The Nifilum be comin' at ye!
 Respond to this message

Forum Owner

Iain, where in the world have you been?

April 27 2005, 6:39 PM
 Dec 21, 2004 - I give up, Iain April 27, 2005 - Enigma prblem figured out I gave up waiting, and wrote my own: http://www.network54.com/Forum/message?forumid=229185&messageid=1104359939 Mac
 Respond to this message
Iain

*I meant a QB GUI, ie all ASCII.

November 2 2006, 6:58 PM
 *
 Respond to this message

Forum Owner

Hi, Iain

November 3 2006, 5:46 AM
 How about looking at this one: http://www.network54.com/Forum/message?forumid=229185&messageid=1104359939 And comparing the encryption results with yours. (Or post your completed program and I can compare) Mac
 Respond to this message

R

March 17 2008, 7:10 PM
 I must admit that this program is what killed my QB interest. I am going to try to make my original version work, and in the process rekindle my QB interest.What is six by seven? Forty-two.
 Respond to this message

Forum Owner

ROFL, Iain

March 17 2008, 9:11 PM

TRUE!
Nov 03 2006 Post

What does 6*7 have to do with anything?

Anyway, good luck. Did you run mine just to see the options?

http://www.network54.com/Forum/message?forumid=229185&messageid=1104359939/

The toughest part is getting it clear in your head how the
machine works.

See you in a year or so, I guess, for the answer.

Mac

 This message has been edited by iorr5t on Mar 17, 2008 9:14 PM

 Respond to this message

Forum Owner

Simulation of a German WWII Cryptographic Center using Enigma

March 17 2008, 10:24 PM
 Iain, I went a little overboard and wrote a system to simulate a whole crypto center. And here is what you can do there: Enter todays date and select a few variables that will set up an Enigma and encrypt a message. This message can be decrypted by any correctly written Enigma simulator or even the actual machine, if you get hold of one. Well, as you can imagine, I would REALLY APPRECIATE IT if you would volunteer to be the only other person in the world to try it out. Please! Mac Click here for explanation you don't have to learn. Just FYI.http://www.network54.com/Realm/NoSee/cc.html DO THIS======= Put the stuff (maybe not the EXE if you don't like EXE's)into some directory and create a file "Army.txt" with thecontent below. Now go to that directory and do QBasic /run cc To the prompt, enter A (army) To the date prompt, enter 19430506. (That is a legal date found in army.txt. Enter a message for me to decrypt! It will look like this:19430506-PGA SVYYK OWRST UPHVP BR Send it to me! I will decrypt it. Mac =============== content of Army.txt ===================19430501-ZDP BIII-I-II12-24-01 OF YB CN DU TG EQ AW XM SL KZ19430502-HDL BIII-IV-I25-15-10 XR MF BK SA VE NY UQ DH LW IC19430503-YLM CIV-II-I17-13-11 HK DE OU WA YV NG SP TR MF ZI19430504-YYI BII-I-IV04-15-06 IJ YN MA DS PU ZL KO FX VQ CW19430505-ZLR BV-IV-I18-19-04 VQ RB EP NS IO YH KX MW JD UG19430506-XJM BV-II-III24-20-17 MR TU XI BH JN SZ FA CV EG WK19430507-MLS BIII-IV-II19-17-18 UN XA TD VH CP RG FB ZO IM WL19430508-GUD BIV-II-III12-01-11 EO VY HM QX WA PN JF UL TG SI19430509-ZIL BV-III-IV10-24-17 IF EQ BT JG PZ WV LS NR YC MA19430510-XAO BI-V-IV06-18-06 ML FZ GB YN TE PU QR DO WX VI19430511-RBK BIV-I-II06-08-03 VP KU OG CE TF JI SA QX YD MH19430512-EOO BV-III-II08-23-02 KC NO IG XL YD VB HU AZ FS MQ19430513-VEL CV-I-III08-06-09 FI YZ TV LQ UG OP WE AN DJ SH19430514-FJV BV-IV-III26-04-21 DC QH AN TG YX SZ EB FO LI PU19430515-LJF BV-IV-I15-08-04 GY SJ KT PN CW BO DA FZ VM IU19430516-QEU BIV-V-II08-25-14 FD IA ZK XG CR HB WN EL PY UT19430517-QVO BIV-V-II13-17-10 ZS OV ED MG TR BU IJ QL CP NW19430518-XZR BIII-II-IV13-04-08 AE LF DP SG MB CO QR UK JV ZN19430519-CUC BI-III-V11-17-13 SY UO NA TH GQ CJ XR MP ZK IL19430520-YTJ BI-V-II12-11-10 EX CP JZ MU YD KQ SR OV IL BG19430521-SEU BV-III-IV05-09-02 KI BT VU RF QW ZM LY HN XD PG19430522-MRS BII-IV-V08-25-23 GJ LA BQ TP EO YM WD VF CZ RN19430523-AXG BI-II-III15-21-05 YR SQ AP EH NZ ML DU GW OB KF19430524-QTB BI-IV-II24-19-08 QG CJ IP HV ST RE DM YB NA LU19430525-QML BII-V-I23-21-02 IV EW GT JP LN OK AR MZ QX SU19430526-NKU CI-IV-III08-04-25 EQ SV MP LX IA TF DN RY BO ZU19430527-XOB BI-IV-V06-07-12 VK ID PA MH RX UZ TW CF YN EL19430528-NVU BI-III-IV05-13-12 GH DX TY ER LV BC UZ WQ OM NJ19430529-HGC BIV-III-I09-19-05 KX FJ GW ES HV PT UY CO QR LB19430530-ZNA BIII-I-IV13-12-06 WO BD LF UG KE IP NQ HA SX YV19430531-VVG CII-V-I21-23-19 FZ LH GP BR WC NX KI DQ VM OS
 Respond to this message
 Current Topic - Any suggestions for improvement? This is a simulation of the Enigma.