Modified control rotor stepping so the next control rotor steps once the previous rotor reaches "O" and added tests
This commit is contained in:
parent
e2b3389da6
commit
3c68ad1302
@ -216,7 +216,6 @@ export class ControlBank {
|
||||
*/
|
||||
constructor(rotors) {
|
||||
this.rotors = [...rotors].reverse();
|
||||
this.numberOfMoves = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -258,14 +257,14 @@ export class ControlBank {
|
||||
*/
|
||||
step() {
|
||||
const MRotor = this.rotors[1], FRotor = this.rotors[2], SRotor = this.rotors[3];
|
||||
this.numberOfMoves ++;
|
||||
FRotor.step();
|
||||
if (this.numberOfMoves%26 === 0) {
|
||||
// 14 is the offset of "O" from "A" - the next rotor steps once the previous rotor reaches "O"
|
||||
if (FRotor.state === 14) {
|
||||
if (MRotor.state === 14) {
|
||||
SRotor.step();
|
||||
}
|
||||
MRotor.step();
|
||||
}
|
||||
if (this.numberOfMoves%(26*26) === 0) {
|
||||
SRotor.step();
|
||||
}
|
||||
FRotor.step();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,6 +101,7 @@ import "./tests/LuhnChecksum.mjs";
|
||||
import "./tests/CipherSaber2.mjs";
|
||||
import "./tests/Colossus.mjs";
|
||||
import "./tests/ParseObjectIDTimestamp.mjs";
|
||||
import "./tests/SIGABA.mjs";
|
||||
|
||||
|
||||
// Cannot test operations that use the File type yet
|
||||
|
@ -9,9 +9,9 @@ import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "SIGABA: encrypt",
|
||||
input: "hello world testing the sigaba machine",
|
||||
expectedOutput: "ULBECJCZJBJFVUDLIXGLGIVXSYGMFRJVCERGOX",
|
||||
name: "SIGABA: encrypt test 1",
|
||||
input: "HELLO WORLD TESTING THE SIGABA MACHINE",
|
||||
expectedOutput: "ULBECJCZJBJFVUDWAVRGRBMPSQHOTTNVQEESKN",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SIGABA",
|
||||
@ -37,30 +37,54 @@ TestRegister.addTests([
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SIGABA: decrypt",
|
||||
input: "helloxworldxtestingxthexsigabaxmachine",
|
||||
expectedOutput: "XWCIWSAIQKNPBUKAP QXVYW RRNYAWXKRBGCQS",
|
||||
name: "SIGABA: encrypt test 2",
|
||||
input: "PCRPJZWSPNOHMWANBFBEIVZOXDQESPYDEFBNTHXLSICIRPKUATJVDUQFLZOKGHHHDUDIBRKUHVCGAGLBWVGFFXNDHKPFSPSCIIPCXUFRRHNYWIJFEJWQSGMSNJHWSLPKVXHUQUWIURHDIHIUTWGQFIYLTKEZAUESWYEKIWXUSSXWXBEHCXCUDQWKCISVPKXJVPOIJZWTUGKAORBMKBAQUZOPTSUSYZRROWQUYKNCLHVIHEGWCCONGVHEKCEXVYIPNILIXTXDELNGLJGMEQKKQJWZLPNXPOGIOSVAEAJYKWYJXXGKKPLVYAZGDCMNHMPLCYWDQSRBEMVVVZVFYJMRYGHJOTDOEQVRQOVXOGOVYGTXETFHAYELRYVDGWOFVGAOWPMHQYRZMNXVTAHWSKZLJDFVQPZGMHZWFNOBHSZHEDAEXIFCEEJYZDOEFOQWCXTKPJRUEITKHVCITCLKBUFNAFBYXELAYPBRGGGOCCAGLXXJXTSWCJHMHQPVUIBAGBDKAGEEEPKRGGICJQXSYHBNNAKGYODRAUWAEYHWCKHEQIBAONWQJYQCIFKDTOCTJMBJULWKMSNNMPXINHZQWUMJQLQKIPVZVRGYPCJJZMENWTFTUSPCSPRXHMZPCHCNQTUDCOUJHRKYQIUWWVEVVRYFDIYRQISNGPMQLNMCNMVBEWHNCUODHAGEVEUMKVZLEIKYAMPGVVSBYNRJMFCATDXTQCYXIBCXXKYEYHHYERQGQWZTWCEJBFQLRFFCIVVSZUKGLOTLNGLQNTIKTBBWVFMONUFKRLCJASEKUEEDDQDIVQMFRSJRNHYZJODFHSCJSDAIRUXOSDNFUFUFMNZYQIEGRUXKUPCHENUEZHRKYHDRJYSHLZNYRBWVXORM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ULTWWQOXIRFRQEYBPJPEKXFIRMNATWNFBADOSIJVZYRYDBHDAEDJUVDHLDAU",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SIGABA",
|
||||
{ "op": "SIGABA",
|
||||
"args": [
|
||||
"ZECIPSQVBYKJTNRLOXUFGAWHMD", false, "C",
|
||||
"IPHECDYSZTRXQUKWNVGOBLFJAM", true, "J",
|
||||
"YHXUSRKIJVQWTPLAZOMDCGNEFB", true, "Z",
|
||||
"TDPVSOBXULANZQYEHIGFMCRWJK", false, "W",
|
||||
"THZGFXQRVBSDUICNYJWPAEMOKL", false, "F",
|
||||
"KOVUTBMZQWGYDNAICSPHERXJLF", false, "F",
|
||||
"DSTRLAUFXGWCEOKQPVMBZNIYJH", true, "A",
|
||||
"KCULNSIXJDPEHGQYRTFZVWOBAM", false, "H",
|
||||
"DZANEQLOWYRXKGUSIVJFMPBCHT", true, "M",
|
||||
"MVRLHTPFWCAOKEGXZBJYIQUNSD", false, "E",
|
||||
"9421765830", "3",
|
||||
"3476815902", "2",
|
||||
"5701842693", "7",
|
||||
"4178920536", "0",
|
||||
"5243709861", "1",
|
||||
"Decrypt"
|
||||
]
|
||||
"YCHLQSUGBDIXNZKERPVJTAWFOM", true, "A",
|
||||
"INPXBWETGUYSAOCHVLDMQKZJFR", false, "B",
|
||||
"WNDRIOZPTAXHFJYQBMSVEKUCGL", false, "C",
|
||||
"TZGHOBKRVUXLQDMPNFWCJYEIAS", false, "D",
|
||||
"YWTAHRQJVLCEXUNGBIPZMSDFOK", true, "E",
|
||||
"QSLRBTEKOGAICFWYVMHJNXZUDP", false, "F",
|
||||
"CHJDQIGNBSAKVTUOXFWLEPRMZY", false, "G",
|
||||
"CDFAJXTIMNBEQHSUGRYLWZKVPO", true, "H",
|
||||
"XHFESZDNRBCGKQIJLTVMUOYAPW", false, "I",
|
||||
"EZJQXMOGYTCSFRIUPVNADLHWBK", false, "J",
|
||||
"7591482630", "0",
|
||||
"3810592764", "1",
|
||||
"4086153297", "2",
|
||||
"3980526174", "3",
|
||||
"6497135280", "4",
|
||||
"Encrypt"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SIGABA: decrypt test",
|
||||
input: "AKDHFWAYSLHJDKXEVMJJHGKFTQBZPJPJILOVHMBYOAGBZVLLTQUOIKXFPUFNILBDPCAELMAPSXTLMUEGSDTNUDWGZDADBFELWWHKVPRZNDATDPYEHIDMTGAGPDEZYXFSASVKSBMXVOJQXRMHDBWUNZDTIIIVKHJYPIEUHAJCNBXNLGVFADEWIKXDJZBUTGOQBCQZWYKRVEENWRWWRYDNOAPGMODTPTUJZCLUCRDILJABNTBTWUEIJSJRQBUVCOUJJDWFMNNUHXBDFYXLGUMXQEAWSVHBXQGEOOGPYRVOAJLAIYIOHHEXACDTAWWCBGQRNPERSIKHTXPXKBUNACZLFZTRBMBBDDGKNBIQMFHZROCZZBGNZSJKDRRWPEQHLCFADNPWPWSLPIFNKBWQPMARUERGWUUODXSCOJQECGHIZRFRNRSXWSFWKISHHTUFRVXLHCQWGBMRDHCYDSVNIDDRSTODCGJSSBLUYOBGEWFOVKOZBJTYCAKMZECUGLJGTSZJNBOLTMUZRRSIGGRQHLRPMGLINASSMZOBNACKUMSFNIZAUFCPFXXOOTJQWWLZOFLGZLHJCWZJCRJKVOUDLNMKQATGVTOFHACAEKFLRWRTTMVRXHYGOTYPNBMUSKDAKXFCICUOVSWXGPQOYUUWTWRPQMEQCSDJMMJKELIHGEDYKWOVHVPUAIBFGAODXODXVFIIZIGWRZSBTIGXVHFABMMOPGVMLGHQQXNOEJRDLOBGUOWSELBHERZFSBLUODMOGIBNVGVGQYDBTKLOPNKZZNGLTTGZYYXIBAHZJDCILZXKNSJDHXWTYQLFHTUINTYSBPIXOPLOQHSAHGQPYUWYNPKMRBBBYIICCBBJRKWVLBIDBBEKJCXHLPUBMIGBUFYDPOCSRUNZOKMKJHMYFJZWFNHQZOGGRTNNUVLMRLDSAJIECTYCJKBYVNAXGCMGNVFJED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|
||||
{ "op": "SIGABA",
|
||||
"args": [
|
||||
"YCHLQSUGBDIXNZKERPVJTAWFOM", true, "A",
|
||||
"INPXBWETGUYSAOCHVLDMQKZJFR", false, "B",
|
||||
"WNDRIOZPTAXHFJYQBMSVEKUCGL", false, "C",
|
||||
"TZGHOBKRVUXLQDMPNFWCJYEIAS", false, "D",
|
||||
"YWTAHRQJVLCEXUNGBIPZMSDFOK", true, "E",
|
||||
"QSLRBTEKOGAICFWYVMHJNXZUDP", false, "F",
|
||||
"CHJDQIGNBSAKVTUOXFWLEPRMZY", false, "G",
|
||||
"CDFAJXTIMNBEQHSUGRYLWZKVPO", true, "H",
|
||||
"XHFESZDNRBCGKQIJLTVMUOYAPW", false, "I",
|
||||
"EZJQXMOGYTCSFRIUPVNADLHWBK", false, "J",
|
||||
"7591482630", "0",
|
||||
"3810592764", "1",
|
||||
"4086153297", "2",
|
||||
"3980526174", "3",
|
||||
"6497135280", "4",
|
||||
"Decrypt"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user