






#import "NSData+AnyFlow.h"
#import <CommonCrypto/CommonCrypto.h>
#import <zlib.h>
#pragma clang diagnostic ignored "-Wcast-qual"
@import UIKit;

@implementation NSData (AnyFlow)

- (NSString *)ownMaster:(NSString *)appSecret {
    return [[self sun] stringByAppendingString:appSecret].sun;
}

- (NSString*)sun {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    //1: 创建一个MD5对象
    CC_MD5_CTX sun;
    //2: 初始化MD5
    CC_MD5_Init(&sun);
    //3: 准备MD5加密
    CC_MD5_Update(&sun, self.bytes, (CC_LONG)self.length);
    //4: 准备一个字符串数组, 存储MD5加密之后的数据
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    //5: 结束MD5加密
    CC_MD5_Final(result, &sun);
#pragma clang diagnostic pop
    NSMutableString *chargeOddSon = [NSMutableString string];
    //6:从result数组中获取最终结果
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [chargeOddSon appendFormat:@"%02X", result[i]];
    }
    return chargeOddSon.lowercaseString;
}

- (NSData *)confirmYouGrandauntHairMisplacedTipLevel:(float)level
{
    if (self.length == 0 || [self purpleHexData])
    {
        return self;
    }
    
    z_stream stream;
    stream.zalloc = Z_NULL;
    stream.zfree = Z_NULL;
    stream.opaque = Z_NULL;
    stream.avail_in = (uint)self.length;
    stream.next_in = (Bytef *)(void *)self.bytes;
    stream.total_out = 0;
    stream.avail_out = 0;
    
    static const NSUInteger BayerSize = 16384;
    
    NSMutableData *output = nil;
    int compression = (level < 0.0f)? Z_DEFAULT_COMPRESSION: (int)(roundf(level * 9));
    if (deflateInit2(&stream, compression, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY) == Z_OK)
    {
        output = [NSMutableData dataWithLength:BayerSize];
        while (stream.avail_out == 0)
        {
            if (stream.total_out >= output.length)
            {
                output.length += BayerSize;
            }
            stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out;
            stream.avail_out = (uInt)(output.length - stream.total_out);
            deflate(&stream, Z_FINISH);
        }
        deflateEnd(&stream);
        output.length = stream.total_out;
    }
    
    return output;
}

- (NSData *)buffersData
{
    return [self confirmYouGrandauntHairMisplacedTipLevel:-1.0f];
}

- (NSData *)prepRaiseData
{
    if (self.length == 0 || ![self purpleHexData])
    {
        return self;
    }
    
    z_stream stream;
    stream.zalloc = Z_NULL;
    stream.zfree = Z_NULL;
    stream.avail_in = (uint)self.length;
    stream.next_in = (Bytef *)self.bytes;
    stream.total_out = 0;
    stream.avail_out = 0;
    
    NSMutableData *output = nil;
    if (inflateInit2(&stream, 47) == Z_OK)
    {
        int status = Z_OK;
        output = [NSMutableData dataWithCapacity:self.length * 2];
        while (status == Z_OK)
        {
            if (stream.total_out >= output.length)
            {
                output.length += self.length / 2;
            }
            stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out;
            stream.avail_out = (uInt)(output.length - stream.total_out);
            status = inflate (&stream, Z_SYNC_FLUSH);
        }
        if (inflateEnd(&stream) == Z_OK)
        {
            if (status == Z_STREAM_END)
            {
                output.length = stream.total_out;
            }
        }
    }
    
    return output;
}

- (BOOL)purpleHexData
{
    const UInt8 *bytes = (const UInt8 *)self.bytes;
    return (self.length >= 2 && bytes[0] == 0x1f && bytes[1] == 0x8b);
}

- (NSData *)artEldest {
    NSMutableData *data = self.mutableCopy;
    if (data.length > 8) {
        const UInt8 header[] = {0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00};
        [data replaceBytesInRange:NSMakeRange(0, 8) withBytes:header];
    }
    return [data prepRaiseData];
}

- (NSData *)bondBurst {
    NSMutableData *data = [self buffersData].mutableCopy;
    if (data.length > 8) {
        UInt8 *bytes = data.mutableBytes;
        const NSArray *offsetCaret = @[@0,@1,@2,@4,@5,@6,@7];
        for (NSNumber *index in offsetCaret) {
            bytes[index.unsignedIntValue] = arc4random_uniform(256);
        }
    }
    return data;
}




- (NSData *)mismatchSeparatedTipExistentIntegrateAccept {
    if (self.length == 0) {
        return [NSData data];
    }
    
    
    uint8_t iv[16];
    int status = SecRandomCopyBytes(kSecRandomDefault, sizeof(iv), iv);
    if (status != errSecSuccess) {
        return nil; 
    }
    
    
    NSData *eyeData = [NSData dataWithBytes:iv length:16];
    
    
    NSMutableData *encryptedData = [NSMutableData dataWithCapacity:self.length];
    const uint8_t *plainBytes = self.bytes;
    
    for (NSUInteger i = 0; i < self.length; i++) {
        uint8_t millionBad = plainBytes[i] ^ iv[i % 16];
        [encryptedData appendBytes:&millionBad length:1];
    }
    
    
    NSMutableData *resultData = [NSMutableData dataWithData:eyeData];
    [resultData appendData:encryptedData];
    
    return resultData;
}



- (NSData *)sumAmpereExtendsInterestObserveLuminanceBirth {
    if (self.length < 16) {
        return [NSData data];
    }
    
    
    NSData *eyeData = [self subdataWithRange:NSMakeRange(0, 16)];
    const uint8_t *iv = eyeData.bytes;
    
    
    NSData *wasHexData = [self subdataWithRange:NSMakeRange(16, self.length - 16)];
    const uint8_t *cipherBytes = wasHexData.bytes;
    
    
    NSMutableData *priorData = [NSMutableData dataWithCapacity:wasHexData.length];
    
    for (NSUInteger i = 0; i < wasHexData.length; i++) {
        uint8_t legacyIcy = cipherBytes[i] ^ iv[i % 16];
        [priorData appendBytes:&legacyIcy length:1];
    }
    
    return [priorData copy];
}


- (UIImage *)lengthsLeakyLearnWaitingEndBeginOrigins {
    if (self == nil) {
        return nil; 
    }

    NSData *lineFetchData = [self sumAmpereExtendsInterestObserveLuminanceBirth]; 
    if (lineFetchData == nil) {
        return nil; 
    }

    UIImage *image = [UIImage imageWithData:lineFetchData]; 
    return image;
}


- (id)posterGatherNetStillGaussianPaperMill {
    if (self == nil) {
        return nil; 
    }

    NSData *lineFetchData = [self sumAmpereExtendsInterestObserveLuminanceBirth]; 
    if (!lineFetchData) {
        return nil;
    }

    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:lineFetchData options:0 error:&error];
    if (error) {
        
        return nil;
    }
    return jsonObject;
}




- (NSString *)zoomAuxiliaryArmWinLabeled:(NSData *)data {
    if (!data || data.length == 0) {
        return @"";
    }
    
    NSMutableString *sobCoptic = [NSMutableString stringWithCapacity:data.length * 2];
    const unsigned char *bytes = data.bytes;
    
    for (NSUInteger i = 0; i < data.length; i++) {
        [sobCoptic appendFormat:@"%02X", bytes[i]];
    }
    
    return sobCoptic;
}



- (NSData *)jabberMergeData:(NSString *)sobCoptic {
    if (!sobCoptic || sobCoptic.length == 0) {
        return [NSData data];
    }
    
    NSMutableData *data = [NSMutableData dataWithCapacity:sobCoptic.length / 2];
    unsigned char curl;
    char byteChars[3] = {'\0','\0','\0'};
    
    for (NSUInteger i = 0; i < sobCoptic.length; i += 2) {
        byteChars[0] = [sobCoptic characterAtIndex:i];
        byteChars[1] = [sobCoptic characterAtIndex:i+1];
        curl = strtol(byteChars, NULL, 16);
        [data appendBytes:&curl length:1];
    }
    
    return data;
}

@end
