Created
June 1, 2017 14:53
-
-
Save fiddyspence/4ca9845d67edd200cb5c4b9e1d613a5f to your computer and use it in GitHub Desktop.
cryptopals 1.5
This file contains 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 ( | |
"fmt" | |
"encoding/hex" | |
"strings" | |
) | |
func main () { | |
cleartext := []byte(fmt.Sprintf("Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal")) | |
dst := make([]byte, len(cleartext)) | |
initkey := rotatekey(dst[0]) | |
for i, c := range cleartext { | |
dst[i] = c ^ initkey | |
initkey = rotatekey(initkey) | |
} | |
output := make([]byte, hex.EncodedLen(len(dst))) | |
hex.Encode(output, dst) | |
fmt.Printf("%s\n", output) | |
} | |
func rotatekey (inchar byte) byte { | |
bytearray := []byte("ICE") | |
switch string(inchar) { | |
case "I": | |
return bytearray[1] | |
case "C": | |
return bytearray[2] | |
case "E": | |
return bytearray[0] | |
default: | |
return bytearray[0] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment