Pure Go implementation of Shannon stream cipher. No-brainer port of rust-shannon.
Shannon cipher is used in Spotify Connect to encrypt communication between player and Spotify AP server. Shannon cipher is variant of Sober stream cipher.
Encryption
import "github.com/chatoooo/shannon"
...
key := []byte{0x65, 0x87, 0xd8, 0x8f, 0x6c, 0x32, 0x9d, 0x8a, 0xe4, 0x6b}
message := []byte("My secret message")
cipher := shannon.New(key)
cipher.Encrypt(message)
// message contains ciphertext now
mac := make([]byte, 16)
cipher.Final(mac)
// mac contains MAC of the message
Decryption
import "github.com/chatoooo/shannon"
...
key := []byte{0x65, 0x87, 0xd8, 0x8f, 0x6c, 0x32, 0x9d, 0x8a, 0xe4, 0x6b}
// message is encrypted
message := []byte{0x91, 0x9d, 0xa9, 0xb6, 0x29, 0xfc, 0x9c, 0xdd, 0x17, 0x8c, 0x15, 0x31, 0x9a, 0xae, 0xcc, 0x6e, 0xd4}
receivedMac := []byte{0xbe, 0x7b, 0xef, 0x39, 0xee, 0xfe, 0x54, 0xfd, 0x8d, 0xb0, 0xbc, 0x6f, 0xd5, 0x30, 0x35, 0x19}
cipher := shannon.New(key)
cipher.Decrypt(message)
// message contains plaintext now
mac := make([]byte, 16)
if cipher.CheckMac(receivedMac) == nil {
fmt.Println("MAC OK")
}