Created
April 8, 2018 17:57
-
-
Save figgyc/f25b7c1af220a09bb66646bf2897b0f1 to your computer and use it in GitHub Desktop.
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 ( | |
| "encoding/hex" | |
| "fmt" | |
| "github.com/JulianDuniec/crc7" | |
| ) | |
| func main() { | |
| /* | |
| 1) Take your id1 | |
| 24A90106478089A4534C303800035344 | |
| 2) Split it into u16 chunks | |
| 24A9 0106 4780 89A4 534C 3038 0003 5344 | |
| 3) Reverse them backwards | |
| 5344 0003 3038 534C 89A4 4780 0106 24A9 | |
| 4) Endian flip each of those chunks | |
| 4453 0300 3830 4C53 A489 8047 0601 A924 | |
| 5) Shuffle them around with the table on 3dbrew (backwards!) | |
| 0601 A924 A489 8047 3830 4C53 4453 0300 | |
| 6) Join them together | |
| 0601A924A489804738304C5344530300 <-- cid | |
| */ | |
| id1s := "24A90106478089A4534C303800035344" | |
| id1, err := hex.DecodeString(id1s) | |
| if err != nil { | |
| return | |
| } | |
| var chunks [8][2]byte | |
| for i := 0; i < 8; i++ { | |
| chunks[i][0] = id1[i*2] | |
| chunks[i][1] = id1[(i*2)+1] | |
| } | |
| var rchunks [8][2]byte | |
| for i := 0; i < 8; i++ { | |
| rchunks[7-i] = chunks[i] | |
| } | |
| var echunks [8][2]byte | |
| for i := 0; i < 8; i++ { | |
| echunks[i][0] = rchunks[i][1] | |
| echunks[i][1] = rchunks[i][0] | |
| } | |
| var schunks [8][2]byte | |
| /* 3dbrew: | |
| Input CID u16 index Output CID u16 index | |
| 6 0 | |
| 7 1 | |
| 4 2 | |
| 5 3 | |
| 2 4 | |
| 3 5 | |
| 0 6 | |
| 1 7 | |
| */ | |
| schunks[6] = echunks[0] | |
| schunks[7] = echunks[1] | |
| schunks[4] = echunks[2] | |
| schunks[5] = echunks[3] | |
| schunks[2] = echunks[4] | |
| schunks[3] = echunks[5] | |
| schunks[0] = echunks[6] | |
| schunks[1] = echunks[7] | |
| var cid [16]byte | |
| for i := 0; i < 8; i++ { | |
| fmt.Println(i, i*2, (i*2)+1, rchunks[i][0], rchunks[i][1]) | |
| cid[i*2] = rchunks[i][0] | |
| cid[(i*2)+1] = rchunks[i][1] | |
| } | |
| hash := crc7.ComputeHash(cid[:]) | |
| fmt.Println(hex.EncodeToString(cid[:]), schunks, echunks, hash) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment