From faecbad685c06aa7c27c5e7a953f0cfdd37edb2d Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Wed, 25 Nov 2020 21:15:48 -0500 Subject: challenge: c08: update C8 Show the 16-byte block that occurs more than once in the cipher text. --- challenge/c08.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'challenge/c08.go') 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 { -- cgit v1.2.3