github.com/mangodowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/src/crypto/cipher/xor_test.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package cipher
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  )
    11  
    12  func TestXOR(t *testing.T) {
    13  	for alignP := 0; alignP < 2; alignP++ {
    14  		for alignQ := 0; alignQ < 2; alignQ++ {
    15  			for alignD := 0; alignD < 2; alignD++ {
    16  				p := make([]byte, 1024)[alignP:]
    17  				q := make([]byte, 1024)[alignQ:]
    18  				d1 := make([]byte, 1024+alignD)[alignD:]
    19  				d2 := make([]byte, 1024+alignD)[alignD:]
    20  				xorBytes(d1, p, q)
    21  				safeXORBytes(d2, p, q)
    22  				if !bytes.Equal(d1, d2) {
    23  					t.Error("not equal")
    24  				}
    25  			}
    26  		}
    27  	}
    28  }