diff options
author | siddharth <s@ricketyspace.net> | 2021-10-05 20:38:37 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-10-05 20:38:37 -0400 |
commit | 21d8ade047ff938df52b7a1d85c65fcc9147db81 (patch) | |
tree | f1a532a022d932dc37faae62f7bed8ddbf9bf737 /challenge/c28.go | |
parent | 7516fe8a2adc5dc64acb8beb15b956d9605ca443 (diff) |
challenge: do challenge 28
Diffstat (limited to 'challenge/c28.go')
-rw-r--r-- | challenge/c28.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/challenge/c28.go b/challenge/c28.go new file mode 100644 index 0000000..7a763d5 --- /dev/null +++ b/challenge/c28.go @@ -0,0 +1,59 @@ +// Copyright © 2021 rsiddharth <s@ricketyspace.net> +// SPDX-License-Identifier: ISC + +package challenge + +import ( + "fmt" + + "ricketyspace.net/cryptopals/lib" +) + +func C28() { + msg := lib.StrToBytes(`Nobody knows, why we keep tryin' +Why we keep tryin' + +And so on it goes, I'm looking forward +To the next letter that I'm gonna get from you + +A baby is born, as a man lay dying +As a man lay dying + +And so on it goes, I'm looking forward +To the next letter that I'm gonna get from you + +Sit beside me, watch the world burn +We'll never learn, we don't deserve nice things + +And we'll scream, self-righteously +We did our best but what does that really mean + +I'm walkin' around, walkin' around +With my head down, my head down + +I'm pushin' away, I'm pushin' away +Yeah I'm pushin' away, pushin' away`) + sec := lib.StrToBytes("Milk Records") + + // Generate SHA1 MAC. + mac := lib.Sha1Mac(sec, msg) + + // Verify. + if lib.Sha1MacVerify(sec, msg, mac) != true { + fmt.Printf("Error: Sha1Mac verification failed!\n") + return + } + + // Modify msg + msg[42] = byte(42) + + // Verify that SHA1 MAC fails + if lib.Sha1MacVerify(sec, msg, mac) != false { + fmt.Printf("Error: Sha1Mac verification success!\n") + return + } + fmt.Printf("OK\n") +} + +// Output: +// OK |