diff options
author | rsiddharth <s@ricketyspace.net> | 2020-11-25 21:15:48 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-11-25 21:15:48 -0500 |
commit | faecbad685c06aa7c27c5e7a953f0cfdd37edb2d (patch) | |
tree | 11a4122bf1bbcb94b384865866893c82ee8da80e | |
parent | 0d8a5d25dae095a18713105f8fedfb560fe2b16d (diff) |
challenge: c08: update C8
Show the 16-byte block that occurs more than once in the cipher text.
-rw-r--r-- | challenge/c08.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/challenge/c08.go b/challenge/c08.go index b8c9e10..c31024b 100644 --- a/challenge/c08.go +++ b/challenge/c08.go @@ -12,21 +12,25 @@ func C8() { for i := 0; i < len(c08); i++ { bs := lib.StrToBytes(c08[i]) - if isECB(bs) { - fmt.Printf("Cipher at %d (%s) might be AES-ECB\n", i, c08[i]) + block := isECB(bs) + if block != nil { + fmt.Printf("Cipher at line %d (%s)", i+1, c08[i]) + fmt.Printf(" might be AES encrypted in ECB mode.\n") + fmt.Printf("16-byte block '%s'", block) + fmt.Printf(" occurs twice in this cipher.\n") } } } -func isECB(bs []byte) bool { +func isECB(bs []byte) []byte { blocks := lib.BreakIntoBlocks(bs, 16) for i := 0; i < len(blocks); i++ { if hasMatchingBlock(i, blocks) { - return true + return blocks[i] } } - return false + return nil } func hasMatchingBlock(id int, blocks [][]byte) bool { |