aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-06-04 18:06:26 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-06-04 18:06:26 +0200
commit2ba078c156526cb6e170623870aed1db2be95728 (patch)
treef51a3c49d7624456b7200c54808999e2e0fd6154
Initial import
-rw-r--r--README1
-rw-r--r--serial.go45
2 files changed, 46 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..7cc57a7
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+http://www.nesssoftware.com/home/mwc/source.php
diff --git a/serial.go b/serial.go
new file mode 100644
index 0000000..0145117
--- /dev/null
+++ b/serial.go
@@ -0,0 +1,45 @@
+package main
+
+import "fmt"
+
+var (
+ magic1 = []int{
+ 275, 341, 547, 745, 395, 846, 172, 598, 785,
+ }
+ magic2 = []int{
+ 211, 463, 371, 185, 782, 146, 857, 143, 846,
+ }
+ magic3 = []int{
+ 17125, 12417, 14983, 1311, 16985, 13198, 12254, 15197, 14365,
+ }
+ serials = []string{
+ "127517125",
+ "234112417",
+ "354714983",
+ "474501311",
+ "539516985",
+ "684613198",
+ "717212254",
+ "859815197",
+ "978514365",
+ }
+)
+
+func Check(s string) bool {
+ var c, susp, suspen int
+ if len(s) != 9 {
+ return false
+ }
+ n, _ := fmt.Sscanf(s, "%1d%3d%5d", &c, &susp, &suspen)
+ if n != 3 || c < 1 {
+ return false
+ }
+ c -= 1
+ return ((suspen ^ magic3[c]) % magic2[c]) == (susp ^ magic1[c])
+}
+
+func main() {
+ for _, s := range serials {
+ fmt.Println(s, Check(s))
+ }
+}