Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiddyspence/4ca9845d67edd200cb5c4b9e1d613a5f to your computer and use it in GitHub Desktop.
Save fiddyspence/4ca9845d67edd200cb5c4b9e1d613a5f to your computer and use it in GitHub Desktop.
cryptopals 1.5
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