Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有用于iOS的ASCI85/base85编码器/解码器吗?_Ios_Objective C_Base85 - Fatal编程技术网

有用于iOS的ASCI85/base85编码器/解码器吗?

有用于iOS的ASCI85/base85编码器/解码器吗?,ios,objective-c,base85,Ios,Objective C,Base85,这似乎不再是一个问题,但是 有人有编码器/解码器的实现或知道库吗 PS:BASE85用于这里是我自己做的objective-c移植。它起作用了 static unsigned long pow85[] = { 85*85*85*85, 85*85*85, 85*85, 85, 1 }; void wput(unsigned char* output, unsigned long tuple, int bytes) { for( int i=0; i<bytes; i++ ) ou

这似乎不再是一个问题,但是

有人有编码器/解码器的实现或知道库吗


PS:BASE85用于

这里是我自己做的objective-c移植。它起作用了

static unsigned long pow85[] = {
85*85*85*85, 85*85*85, 85*85, 85, 1
};

void wput(unsigned char* output, unsigned long tuple, int bytes) {
for( int i=0; i<bytes; i++ )
    output[i] = (tuple>>((3-i)*8)) & 0xFF;
}

int decode85(const char* input, unsigned char *output) {
unsigned long tuple = 0;
int c, count = 0, posInput = 0, posOutput = 0;
for (;;)
    switch (c = input[posInput++]) {
        default:
            if (c < '!' || c > 'u') {
                NSLog(@"bad character in ascii85 region: %#o", c);
                return -1;
            }
            tuple += (c - '!') * pow85[count++];
            if (count == 5) {
                wput(output+posOutput, tuple, 4);
                posOutput += 4;
                count = 0;
                tuple = 0;
            }
            break;
        case 'z':
            if (count != 0) {
                NSLog(@"z inside ascii85 5-tuple");
                return -1;
            }
            output[posOutput++] = '\0';
            output[posOutput++] = '\0';
            output[posOutput++] = '\0';
            output[posOutput++] = '\0';
            break;
        case '~':
            if ((input[posInput] == '>')||(input[posInput] == '\0')) {
                posInput++;
                if (count > 0) {
                    count--;
                    tuple += pow85[count];
                    wput(output+posOutput, tuple, count);
                    posOutput += count;
                }
                c = input[posInput++];
                return posOutput;
            }
            NSLog(@"~ without > in ascii85 section");
            return -1;
        case '\n': case '\r': case '\t': case ' ':
        case '\0': case '\f': case '\b': case 0177:
            break;
        case EOF:
            NSLog(@"EOF inside ascii85 section");
            return -1;
        }
}

我自己也需要一些东西,所以我就写了。请注意,它使用RFC1924字符集,而不是Adobe版本。如果有帮助,请告诉我@MrTJ链路已断开
+(NSData*)decodeAscii85:(NSString*) sEncoded
{
char* sBuffer = (char*)malloc(sEncoded.length+1);
if( ![sEncoded getCString:sBuffer maxLength:(sEncoded.length+1) encoding:NSASCIIStringEncoding] )
{
    free( sBuffer );
    return nil;
}

unsigned char* sOutBuffer = (unsigned char*)malloc(sEncoded.length+1);
int nLength = decode85( sBuffer, sOutBuffer );
free(sBuffer);
if( nLength == -1)
{
    free( sOutBuffer );
    return nil;
}

return [NSData dataWithBytesNoCopy:sOutBuffer length:nLength freeWhenDone:YES];
}