Last active
January 17, 2016 02:38
-
-
Save chazcheadle/3ce4755fd81727cac890 to your computer and use it in GitHub Desktop.
Enigma IV Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| import "strings" | |
| import "regexp" | |
| var wheels = []*Wheel{} | |
| type Wheel struct { | |
| alphabet string | |
| offset int | |
| } | |
| var alphabets = []string{ | |
| "XGBRCJSQIEFTVHYAPOWZNULKMD", | |
| "REHKVMQTFSJNXBWZGDOALCUPIY", | |
| "SUBWDVRFMKHPOLZCGXINQAJEYT", | |
| "YOBEZALKIHRCUFVQWTSMPXGNJD", | |
| "VIWNXUPTCRHJMBZYAKDOLQSEGF", | |
| "DUSYOCQGZALBKFWHJIVEMPXRNT", | |
| "DASQOPELGKUVBTWYRCINHMXJFZ", | |
| "ZFTIKGOPJLYUDHNMAWVSRECXBQ", | |
| "OSADNJLUXCRQZTHEVBGFYIPKWM", | |
| "INFEGJBTMPZSQWUYKRXHCDLVOA", | |
| "OZBNXIALJFRWGKQCDVYMTEUSHP", | |
| "XGWMOVIZDEFYSPBRTJHAQCKULN"} | |
| func assign_wheel_order(wheel_order []int) { | |
| for i := 0; i < len(wheel_order); i++ { | |
| wheel := new(Wheel) | |
| wheel.alphabet = alphabets[wheel_order[i]] | |
| wheels = append(wheels, wheel) | |
| } | |
| } | |
| func assign_wheel_offset(keyphrase string) { | |
| keyphrase = strings.ToUpper(keyphrase) | |
| // fmt.Println("Keyphrase:", keyphrase) | |
| for i := 0; i < len(wheels); i++ { | |
| // fmt.Println(string(keyphrase[i])) | |
| wheels[i].offset = strings.Index(wheels[i].alphabet, string(keyphrase[i])) | |
| // fmt.Println(string(wheels[i].alphabet[wheels[i].offset])) | |
| } | |
| } | |
| func decode_message(message string) { | |
| message = reg.preg_replace('\w', '', message) | |
| fmt.Println(encode_message) | |
| } | |
| func encode_message(message string) { | |
| } | |
| func main() { | |
| wheel_order := []int{0,1,2} | |
| keyphrase := "ABC" | |
| message := "This is a test message" | |
| assign_wheel_order(wheel_order) | |
| assign_wheel_offset(keyphrase) | |
| for i := 0; i < len(wheels); i++ { | |
| fmt.Println(strings.Split(wheels[i].alphabet, "")) | |
| fmt.Println("Wheel",i,"offset:",wheels[i].offset) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment