func main() { input := "We hold these truths to be self evident: that all men are created equal." cipherkey := "MLK" rawinput := []byte(input) rawkey := []byte(cipherkey) ciphertext := bitwise.RXOR(rawinput, rawkey) output := hexstring.Encode(ciphertext) //Test fmt.Printf("Set 1 Challenge 5 \n") if output == "1a296d242220296c3924283f286c393e3838253f6d38226c2f296d3f28202b6c283a2428282239766d38252d396c2c20216c2029236c2c3e286c2e3e282d3929296c283d382d2162" { fmt.Printf("PASS!!\n\n") } else { fmt.Printf("##FAIL##\n\n") } }
func main() { input1 := "f0f0f0" input2 := "0f0f0f" raw1 := hexstring.Decode(input1) raw2 := hexstring.Decode(input2) xord := bitwise.XOR(raw1, raw2) output := hexstring.Encode(xord) fmt.Printf("Set 1 Challenge 2 \n") //Test if output == "ffffff" { fmt.Printf("PASS!!\n\n") } else { fmt.Printf("##FAIL##\n\n") } }
func main() { file := io.Read("./data/6.txt") raw := base64.Decode(file) //fmt.Printf(hexstring.Encode(raw)) KEYSIZE := 2 bestkey := 0 ham := 1000000 // Arbitaray large value for KEYSIZE < 40 { slice1 := raw[0:KEYSIZE] slice2 := raw[KEYSIZE:(KEYSIZE * 2)] distance := (bitwise.HAM(slice1, slice2) / KEYSIZE) if distance <= ham { ham = distance bestkey = KEYSIZE } KEYSIZE++ } print("KEYSIZE: ", bestkey, " HAM: ", ham, "\n") KEYSIZE = bestkey k := 0 var finalkey []byte for k < KEYSIZE { singlekey := 0 l := 0 var m []byte for l < (len(raw) / KEYSIZE) { if (l * KEYSIZE) < (len(raw) - 1) { m = append(m, raw[(l*KEYSIZE)+k]) } l++ } bruteout := bitwise.BRUTEXOR(m) _, insidekey := hexstring.ScoreEnglish(bruteout) singlekey = insidekey finalkey = append(finalkey, byte(singlekey)) //fmt.Printf("%s", bitwise.SBXOR(m, byte(singlekey))) m = nil k++ } fmt.Printf("-----------------------------------------------------\n") fmt.Printf("%s\n", finalkey) fmt.Printf("-----------------------------------------------------") print("\n") //finaloutput := bitwise.RXOR(raw, finalkey) //print(string(finaloutput)) // Hamming Test input1 := "@ @ @ @ @ @ @ @ @ !" input2 := " @ @ @ @ @ @ @ @ @ " testhamming := bitwise.HAM([]byte(input1), []byte(input2)) if testhamming == 37 { print("\n\nPass Hamming Test\n\n") } else { print("\n\n###FAIL###\n\n") } //Test //fmt.Printf("Set 1 Challenge 6 \n") testinput := "f0f0f0" testraw := hexstring.Decode(testinput) testoutput := base64.Encode(testraw) testreverse := base64.Decode(testoutput) testcooked := hexstring.Encode(testreverse) if testcooked == testinput { //fmt.Printf("DING!!!!\n\n") } }