emedvedev / enigma Goto Github PK
View Code? Open in Web Editor NEWEnigma cipher machine emulator (CLI + library) written in Go
Enigma cipher machine emulator (CLI + library) written in Go
I need to persist an Enigma machine to bytes and restore it later. I use this function to save it
func saveEnigmaToFile(machine *enigma.Enigma, filename string) {
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)
enc.Encode(machine)
file, err := os.Create(filename)
defer file.Close()
if err != nil {
log.Fatal(err)
}
file.Write(buf.Bytes())
}
And restore it like this:
var machine2 *enigma.Enigma
machine2, err := loadEnigmaFromFile("machine99.bin")
But the restored machine's configuration is different from what was saved. Using degob
, I see that it was serialized ok (added linefeeds for clarity).
{"Reflector":{"ID":"B",
"Sequence":[24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19]},
"Plugboard":[1,0,3,2,5,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],
"Rotors":[
{"ID":"III",
"StraightSeq":[1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14],
"ReverseSeq":[19,0,6,1,15,2,18,3,16,4,20,5,21,13,25,7,24,8,23,9,22,11,17,10,14,12],
"Turnover":[21],"Offset":0,"Ring":0},
{"ID":"II",
"StraightSeq":[0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4],
"ReverseSeq":[0,9,15,2,25,22,17,11,5,1,3,10,14,19,24,20,16,6,4,13,7,23,12,8,21,18],
"Turnover":[4],"Offset":1,"Ring":0},
{"ID":"IV",
"StraightSeq":[4,18,14,21,15,25,9,0,24,16,20,8,17,7,23,11,13,5,19,6,10,3,2,12,22,1],
"ReverseSeq":[7,25,22,21,0,17,19,13,11,6,20,15,23,16,2,4,9,12,1,18,10,3,24,14,8,5],
"Turnover":[9],"Offset":2,"Ring":0}]}
But the Offset
and Ring
values are alwasy wrong for the second and thrid rotor, regardless of if the machine encrypted something or not.
Is there something special about the Enigma
struct when it comes to serializing and deserializing it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.