Last active
November 10, 2016 11:43
-
-
Save dignifiedquire/b8aee1b2b8a8903d2f96b657ed0cad6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/aes" | |
"crypto/cipher" | |
"bytes" | |
"fmt" | |
) | |
func main() { | |
key := []byte{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5} | |
plaintext1 := bytes.Repeat([]byte{ 47 }, 100) | |
plaintext2 := bytes.Repeat([]byte{ 24 }, 100) | |
plaintext3 := bytes.Repeat([]byte{ 7 }, 100) | |
plaintext4 := bytes.Repeat([]byte{ 25 }, 100) | |
plaintext5 := bytes.Repeat([]byte{ 48 }, 100) | |
block, err := aes.NewCipher(key) | |
if err != nil { | |
panic(err) | |
} | |
ciphertext1 := make([]byte, len(plaintext1)) | |
ciphertext2 := make([]byte, len(plaintext2)) | |
ciphertext3 := make([]byte, len(plaintext3)) | |
ciphertext4 := make([]byte, len(plaintext4)) | |
ciphertext5 := make([]byte, len(plaintext5)) | |
iv := []byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} | |
fmt.Printf("iv: %v\n", iv) | |
fmt.Printf("key: %v\n", key) | |
stream := cipher.NewCTR(block, iv) | |
fmt.Printf("block size: %v\n", aes.BlockSize) | |
fmt.Printf("input1: %v\n", plaintext1) | |
stream.XORKeyStream(ciphertext1, plaintext1) | |
fmt.Printf("input2: %v\n", plaintext2) | |
stream.XORKeyStream(ciphertext2, plaintext2) | |
fmt.Printf("input3: %v\n", plaintext3) | |
stream.XORKeyStream(ciphertext3, plaintext3) | |
fmt.Printf("input4: %v\n", plaintext4) | |
stream.XORKeyStream(ciphertext4, plaintext4) | |
fmt.Printf("input5: %v\n", plaintext5) | |
stream.XORKeyStream(ciphertext5, plaintext5) | |
fmt.Printf("ciphertext1: %v\n", ciphertext1) | |
fmt.Printf("ciphertext2: %v\n", ciphertext2) | |
fmt.Printf("ciphertext3: %v\n", ciphertext3) | |
fmt.Printf("ciphertext4: %v\n", ciphertext4) | |
fmt.Printf("ciphertext5: %v\n", ciphertext5) | |
// Decrypt to be sure things are the same | |
dec1 := make([]byte, len(plaintext1)) | |
stream = cipher.NewCTR(block, iv) | |
stream.XORKeyStream(dec1, ciphertext1) | |
fmt.Printf("output: %v\n", dec1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iv: [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] | |
key: [5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5] | |
block size: 16 | |
input1: [47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47] | |
input2: [24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24] | |
input3: [7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7] | |
input4: [25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25] | |
input5: [48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48] | |
ciphertext1: [121 104 0 151 57 137 22 239 234 151 58 15 100 22 228 110 85 248 249 15 145 128 223 25 192 175 132 169 98 203 231 106 224 102 206 244 29 213 36 2 26 213 94 29 134 219 136 73 212 176 33 95 198 91 148 139 132 252 182 115 116 160 146 194 0 97 181 0 193 149 21 51 248 97 32 62 86 153 238 67 38 34 55 143 70 193 99 107 31 67 90 97 55 63 69 203 33 233 74 237] | |
ciphertext2: [109 172 127 179 110 222 79 219 87 76 70 204 166 110 184 229 90 49 160 252 78 58 73 51 152 218 3 200 10 124 152 117 137 40 23 127 56 57 203 31 101 227 31 198 223 86 98 120 100 86 116 144 142 127 68 175 249 232 22 83 22 68 60 230 146 22 153 193 67 5 51 253 239 210 80 31 254 103 185 145 123 99 205 175 156 144 191 67 31 236 43 98 197 235 31 50 69 228 100 64] | |
ciphertext3: [191 93 126 191 180 42 118 144 28 188 211 191 211 130 170 153 134 240 179 83 75 23 42 68 158 200 123 155 57 169 152 133 33 114 90 29 131 91 70 105 83 45 40 47 77 96 97 8 40 1 110 245 106 172 152 146 5 114 132 0 179 31 44 78 19 109 92 199 226 36 12 74 180 241 224 107 83 13 167 27 251 101 193 98 49 90 225 197 75 213 144 52 235 130 92 247 219 139 209 132] | |
ciphertext4: [191 110 53 190 250 44 190 136 22 209 131 200 112 31 61 183 247 95 4 249 69 147 238 74 18 71 197 115 141 226 102 92 91 128 181 172 67 109 17 165 52 10 55 31 55 225 253 140 154 35 104 62 119 103 197 152 125 134 140 181 170 76 75 114 195 188 68 197 28 47 116 82 34 128 232 122 14 229 122 161 36 212 161 164 145 86 215 233 222 50 143 89 131 32 130 196 109 36 204 254] | |
ciphertext5: [97 142 8 37 69 173 124 180 97 70 45 91 196 126 184 135 213 104 171 89 231 63 43 42 7 245 75 165 205 182 24 50 170 217 128 112 114 215 209 145 135 235 179 212 5 81 142 199 53 221 39 239 167 21 237 168 145 249 250 108 2 247 89 73 228 227 255 155 121 157 205 96 43 32 112 209 173 96 143 43 220 140 26 205 34 34 53 157 41 167 125 235 243 85 13 14 93 109 233 186] | |
output: [47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment