summaryrefslogtreecommitdiffstats
path: root/challenge
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-12-08 17:59:28 -0500
committerrsiddharth <s@ricketyspace.net>2020-12-08 17:59:28 -0500
commitdc6cca42113ea7e9a292175e1704061d742014dd (patch)
tree3b5e2ee16b74a745f70fbb0f0daf3de4101f4fbd /challenge
parent7b29de2661a0a1e59d816544b7176b4ec8201468 (diff)
lib/blocks: move isECB from ch. 8 in here as BlockIsECB
Diffstat (limited to 'challenge')
-rw-r--r--challenge/c08.go25
1 files changed, 1 insertions, 24 deletions
diff --git a/challenge/c08.go b/challenge/c08.go
index 862c070..1f43b45 100644
--- a/challenge/c08.go
+++ b/challenge/c08.go
@@ -12,7 +12,7 @@ func C8() {
for i := 0; i < len(c08); i++ {
bs := lib.HexStrToBytes(c08[i])
- block := isECB(bs)
+ block := lib.BlockIsECB(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")
@@ -27,29 +27,6 @@ func C8() {
// Cipher at line 133 (d880619740a8a19b7840a8a31c810a3d08649af70dc06f4fd5d2d69c744cd283e2dd052f6b641dbf9d11b0348542bb5708649af70dc06f4fd5d2d69c744cd2839475c9dfdbc1d46597949d9c7e82bf5a08649af70dc06f4fd5d2d69c744cd28397a93eab8d6aecd566489154789a6b0308649af70dc06f4fd5d2d69c744cd283d403180c98c8f6db1f2a3f9c4040deb0ab51b29933f2c123c58386b06fba186a) might be AES encrypted in ECB mode.
// 16-byte block '08649af70dc06f4fd5d2d69c744cd283' occurs more than once in this cipher.
-func isECB(bs []byte) []byte {
- blocks := lib.BreakIntoBlocks(bs, 16)
-
- for i := 0; i < len(blocks); i++ {
- if hasMatchingBlock(i, blocks) {
- return blocks[i]
- }
- }
- return nil
-}
-
-func hasMatchingBlock(id int, blocks [][]byte) bool {
- for i := 0; i < len(blocks); i++ {
- if i == id {
- continue
- }
- if lib.BlocksEqual(blocks[i], blocks[id]) {
- return true
- }
- }
- return false
-}
-
var c08 = []string{
"8a10247f90d0a05538888ad6205882196f5f6d05c21ec8dca0cb0be02c3f8b09e382963f443aa514daa501257b09a36bf8c4c392d8ca1bf4395f0d5f2542148c7e5ff22237969874bf66cb85357ef99956accf13ba1af36ca7a91a50533c4d89b7353f908c5a166774293b0bf6247391df69c87dacc4125a99ec417221b58170e633381e3847c6b1c28dda2913c011e13fc4406f8fe73bbf78e803e1d995ce4d",
"bd20aad820c9e387ea57408566e5844c1e470e9d6fbbdba3a6b4df1dd85bce2208f1944f1827d015df9c46c22803f41d1052acb721977f0ccc13db95c970252091ea5e36e423ee6a2f2d12ef909fcadd42529885d221af1225e32161b85e6dc03465cf398c937846b18bac05e88820a567caac113762753dffbe6ece09823bab5aee947a682bb3156f42df1d8dc320a897ee79981cf937390b4ae93eb8657f6c",