mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
763 B
41 lines
763 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
5 years ago
|
"math/bits"
|
||
5 years ago
|
"reflect"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
4 years ago
|
"github.com/01-edu/public/go/tests/lib"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func reverseBits(octet byte) byte {
|
||
|
return bits.Reverse8(uint8(octet))
|
||
|
}
|
||
|
|
||
5 years ago
|
func challengeBytes(fn1, fn2 interface{}, args ...interface{}) {
|
||
5 years ago
|
st1 := lib.Monitor(fn1, args)
|
||
|
st2 := lib.Monitor(fn2, args)
|
||
5 years ago
|
if !reflect.DeepEqual(st1.Results, st2.Results) {
|
||
5 years ago
|
lib.Fatalf("%s(%08b) == %08b instead of %08b\n",
|
||
5 years ago
|
"ReverseBits",
|
||
5 years ago
|
args[0].(byte),
|
||
|
st1.Results[0].(byte),
|
||
|
st2.Results[0].(byte),
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
|
args := []byte{0x26, 0x27, 0x28, 0x29, 0xAA, 0xBB}
|
||
5 years ago
|
|
||
|
for i := 0; i < 10; i++ {
|
||
5 years ago
|
n := lib.RandIntBetween(0, 255)
|
||
5 years ago
|
args = append(args, byte(n))
|
||
|
}
|
||
|
|
||
|
for _, v := range args {
|
||
5 years ago
|
challengeBytes(student.ReverseBits, reverseBits, v)
|
||
5 years ago
|
}
|
||
|
}
|