func edit(ct []byte, offset int, text []byte) { block, err := aes.NewCipher(key) if err != nil { fmt.Println(err) } t := make([]byte, len(ct)) util.CTREncrypt(block, nonce, t, ct) for i := offset; i < offset+len(text) && i < len(t); i++ { t[i] = text[i-offset] } util.CTREncrypt(block, nonce, ct, t) }
func main() { encoded := util.ReadFile("25.txt") bytes, err := base64.StdEncoding.DecodeString(string(encoded)) if err != nil { log.Fatal(err) } oldAes, err := aes.NewCipher([]byte("YELLOW SUBMARINE")) if err != nil { log.Fatal(err) } util.ECBDecrypt(oldAes, bytes, bytes) // we have plaintext in bytes // encrypt it in CTR mode block, err := aes.NewCipher(key) if err != nil { log.Fatal(err) } util.CTREncrypt(block, nonce, bytes, bytes) // save the copy ct := make([]byte, len(bytes)) copy(ct, bytes) // let's prepare sequence of 0 bytes and replace the text with it zeroes := make([]byte, len(bytes)) edit(bytes, 0, zeroes) // result in bytes contains the key // let's recover the original plain text: for i := 0; i < len(ct); i++ { bytes[i] = ct[i] ^ bytes[i] } fmt.Println(string(bytes)) }
func isAdmin(ct []byte) bool { block, _ := aes.NewCipher(key) res := make([]byte, len(ct)) copy(res, ct) util.CTREncrypt(block, nonce, res, res) fmt.Println("isAdmin peek:", string(res)) return bytes.Count(res, []byte(";admin=true;")) > 0 }
func init() { scan := bufio.NewScanner(os.Stdin) block, _ := aes.NewCipher(key) for scan.Scan() { t, _ := base64.StdEncoding.DecodeString(scan.Text()) util.CTREncrypt(block, nonce, t, t) fmt.Println(len(t), hex.EncodeToString(t)) cts = append(cts, t) } fmt.Println("ciphertexts:", len(cts)) }
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) fmt.Println("crypt peek:", string(res)) util.CTREncrypt(block, nonce, res, res) return res }
func init() { scan := bufio.NewScanner(os.Stdin) block, _ := aes.NewCipher(key) minLen = 999999 for scan.Scan() { t, _ := base64.StdEncoding.DecodeString(scan.Text()) util.CTREncrypt(block, nonce, t, t) if len(t) < minLen { minLen = len(t) } cts = append(cts, t) } }
func main() { s, _ := base64.StdEncoding.DecodeString("L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==") block, _ := aes.NewCipher([]byte("YELLOW SUBMARINE")) util.CTREncrypt(block, make([]byte, 16), s, s) fmt.Println(string(s)) }