package obfuscated2

import (
	
	
	
	
)

func (,  []byte) (cipher.Stream, error) {
	,  := aes.NewCipher()
	if  != nil {
		return nil, 
	}
	return cipher.NewCTR(, ), nil
}

func ( []byte) ( [48]byte) {
	copy([:], [8:56])
	// https://github.com/golang/go/wiki/SliceTricks#reversing
	for ,  := 0, len()-1;  < ; ,  = +1, -1 {
		[], [] = [], []
	}

	return
}

// function from https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation
func ( io.Reader) ( [64]byte,  error) {
	// init := (56 random bytes) + protocol + dc + (2 random bytes)
	for {
		_,  = io.ReadFull(, [:])
		if  != nil {
			return [64]byte{}, 
		}

		// Filter some start sequences
		// See https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/jni/tgnet/Connection.cpp#L531.
		// See https://github.com/tdlib/td/blob/master/td/mtproto/TcpTransport.cpp#L157-L158.
		if [0] == 0xef { // Abridged header
			continue
		}

		 := binary.LittleEndian.Uint32([0:4])
		if  == 0x44414548 || // HEAD
			 == 0x54534f50 || // POST
			 == 0x20544547 || // GET
			 == 0x4954504f || // OPTI
			 == 0x02010316 || // ????
			 == 0xdddddddd || // PaddedIntermediate header
			 == 0xeeeeeeee /* Intermediate header */ {
			continue
		}

		if  := binary.LittleEndian.Uint32([4:8]);  == 0 {
			continue
		}

		break
	}

	return , nil
}