from enigmar import EnigmaBuilder
builder = EnigmaBuilder()
builder.rotor("I", 0, 0) builder.rotor("II", 0, 0) builder.rotor("III", 0, 0) builder.reflector("B")
builder.plugboard("AV BS CG DL FU HZ IN KM OW RX")
machine = builder.build()
plaintext = "HELLOWORLD"
ciphertext = machine.process_string(plaintext)
print(f"Plaintext: {plaintext}")
print(f"Ciphertext: {ciphertext}")
builder2 = EnigmaBuilder()
builder2.rotor("I", 0, 0)
builder2.rotor("II", 0, 0)
builder2.rotor("III", 0, 0)
builder2.reflector("B")
builder2.plugboard("AV BS CG DL FU HZ IN KM OW RX")
decoder = builder2.build()
decrypted = decoder.process_string(ciphertext)
print(f"Decrypted: {decrypted}")
assert decrypted == plaintext, "Decryption failed!"
print("\n✓ Reciprocal encryption verified!")
key = decoder.export_key()
print(f"\nExported key (JSON):\n{key[:200]}...")
decoder.process_string("SOMETEXT")
decoder.import_key(key)
print("✓ Key imported, state restored!")
decoder.reset()
print("✓ Machine reset to initial rotor positions")