summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2021-01-26 21:25:22 -0500
committerrsiddharth <s@ricketyspace.net>2021-01-26 21:25:22 -0500
commit34d90886a0ed3aaf2086633efcde45b227ea27ba (patch)
tree3c840fb38c753fa6628fc291c658c4d0c601a653
parent34637327ef1eef55c35286223d2669637c9da25e (diff)
challenge: do challenge 15
-rw-r--r--challenge/c15.go40
-rw-r--r--cryptopals.go2
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge/c15.go b/challenge/c15.go
new file mode 100644
index 0000000..a48b4b4
--- /dev/null
+++ b/challenge/c15.go
@@ -0,0 +1,40 @@
+// Copyright © 2021 rsiddharth <s@ricketyspace.net>
+// SPDX-License-Identifier: ISC
+
+package challenge
+
+import (
+ "fmt"
+ "ricketyspace.net/cryptopals/lib"
+)
+
+func C15() {
+ ice := lib.StrToBytes("ICE ICE BABY")
+ fmt.Printf("ice: %v\n", ice)
+
+ padded_ice := lib.Pkcs7Padding(ice, 16)
+ fmt.Printf("ice padded: %v\n", padded_ice)
+
+ unpadded_ice := lib.Pkcs7PaddingUndo(padded_ice)
+ for i := 0; i < len(ice); i++ {
+ if ice[i] != unpadded_ice[i] {
+ panic("padding undo failed!")
+ }
+ }
+ fmt.Printf("unpadded ice: %v\n", unpadded_ice)
+
+ // Will fail; commented out.
+ // bad_ice := append(ice, []byte{5, 5, 5, 5}...)
+ // fmt.Printf("bad ice: %v\n", bad_ice)
+ // lib.Pkcs7PaddingUndo(bad_ice)
+
+ // Will fail; commented out.
+ // evil_ice := append(ice, []byte{1, 2, 3, 4}...)
+ // fmt.Printf("evil ice: %v\n", evil_ice)
+ // lib.Pkcs7PaddingUndo(evil_ice)
+}
+
+// Output:
+// ice: [73 67 69 32 73 67 69 32 66 65 66 89]
+// ice padded: [73 67 69 32 73 67 69 32 66 65 66 89 4 4 4 4]
+// unpadded ice: [73 67 69 32 73 67 69 32 66 65 66 89]
diff --git a/cryptopals.go b/cryptopals.go
index 179caf0..a5f5e90 100644
--- a/cryptopals.go
+++ b/cryptopals.go
@@ -46,5 +46,7 @@ func main() {
challenge.C13()
case 14:
challenge.C14()
+ case 15:
+ challenge.C15()
}
}