func main() { encoded := util.ReadFile("10.txt") src, _ := base64.StdEncoding.DecodeString(string(encoded)) key := []byte("YELLOW SUBMARINE") iv := make([]byte, 16) block, _ := aes.NewCipher(key) util.CBCDecrypt(block, iv, src, src) util.CBCEncrypt(block, iv, src, src) util.CBCDecrypt(block, iv, src, src) fmt.Println(string(src)) }
func isAdmin(ct []byte) bool { block, _ := aes.NewCipher(key) res := make([]byte, len(ct)) copy(res, ct) util.CBCDecrypt(block, iv, res, res) fmt.Println("isAdmin peek:", string(res)) return bytes.Count(res, []byte(";admin=true;")) > 0 }
func isPadValid(ct, iv []byte) bool { block, _ := aes.NewCipher(key) res := make([]byte, len(ct)) copy(res, ct) util.CBCDecrypt(block, iv, res, res) _, err := util.CheckPadding(res) // fmt.Println(res, err == nil) return err == nil }
func aesDecrypt(s *big.Int, ct, iv []byte) (t []byte) { sum := sha1.Sum([]byte(s.String())) blockA, _ := aes.NewCipher(sum[0:16]) tPadded := make([]byte, len(ct)) util.CBCDecrypt(blockA, iv, tPadded, ct) t, err := util.CheckPadding(tPadded) if err != nil { log.Fatal(err, tPadded) } return }
func decrypt(ct []byte) ([]byte, error) { block, _ := aes.NewCipher(key) res := make([]byte, len(ct)) util.CBCDecrypt(block, key, res, ct) for i := 0; i < len(res); i++ { if res[i] > 127 { return nil, errors.New("Wrong text: " + string(res)) } } return res, nil }