func encryptOracle(src []byte) []byte { key := util.RandAes128() block, _ := aes.NewCipher(key) out := make([]byte, len(src)) copy(out, src) // random prepend and append prefixSize := util.RandByte()%10 + 5 postfixSize := util.RandByte()%10 + 5 postfix := util.RandBytes(int(postfixSize)) out = append(util.RandBytes(int(prefixSize)), out...) out = append(out, postfix...) // padding out = util.PadTo(out, 16) // fmt.Println("before enc", out) // random encryption mode mode := util.RandByte() if mode%2 == 0 { // ecb fmt.Println("ecb") util.ECBEncrypt(block, out, out) } else { // cbc fmt.Println("cbc") iv := util.RandAes128() util.CBCEncrypt(block, iv, out, out) } return out }
func aesCrypt(s *big.Int, t []byte) (ct, iv []byte) { sum := sha1.Sum([]byte(s.String())) blockA, _ := aes.NewCipher(sum[0:16]) tPadded := util.PadTo(t, 16) ct = make([]byte, len(tPadded)) iv = util.RandBytes(16) util.CBCEncrypt(blockA, iv, ct, tPadded) return }
func crypt(userdata []byte) []byte { res := bytes.Replace(userdata, []byte("="), []byte("%3D"), -1) res = bytes.Replace(res, []byte(";"), []byte("%3B"), -1) res = append(prefix, res...) res = append(res, postfix...) block, _ := aes.NewCipher(key) res = util.PadTo(res, 16) util.CBCEncrypt(block, iv, res, res) return res }
func getMsg() (ct, iv []byte) { ct, err := base64.StdEncoding.DecodeString(msgs[util.RandByte()%10]) if err != nil { log.Fatal("Cannot decode", err) } iv = util.RandAes128() block, _ := aes.NewCipher(key) ct = util.PadTo(ct, block.BlockSize()) util.CBCEncrypt(block, iv, ct, ct) return ct, iv }
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)) }