Not explained.
Static
Char base64encodingtable [64] = {
'A', 'B', 'C', 'D', 'E', 'E', 'F', 'G', 'h', 'I', 'J ', 'k', 'l', 'M', 'n', 'O', 'P ',
'Q', 'R', 's', 't', 'U', 'V', 'w', 'x', 'y', 'z ', 'A', 'B', 'C', 'D', 'E', 'E', 'F ',
'G', 'h', 'I', 'J', 'k', 'l', 'M', 'n', 'O', 'P ', 'Q', 'R', 's', 't', 'U', 'V ',
'W', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5 ', '6', '7', '8', '9', '+ ','/'
};
+ (Nsstring *) base64stringfromdata: (nsdata *) Data Length: (INT) length {
Unsigned
Long ixtext, lentext;
Long ctremaining;
Unsigned
Char input [3], output [4];
Short I, charsonline = 0, ctcopy;
Const
Unsigned char * Raw;
Nsmutablestring * result;
Lentext = [Data Length];
If (lentext <1)
Return
@"";
Result = [nsmutablestring stringwithcapacity: lentext];
Raw = [data bytes];
Ixtext = 0;
While (true ){
Ctremaining = lentext-ixtext;
If (ctremaining <= 0)
Break;
For (I = 0; I <3; I ++ ){
Unsigned
Long IX = ixtext + I;
If (IX <lentext)
Input [I] = raw [ix];
Else
Input [I] = 0;
}
Output [0] = (input [0] & 0xfc)> 2;
Output [1] = (input [0] & 0x03) <4) | (input [1] & 0xf0)> 4 );
Output [2] = (input [1] & 0x0f) <2) | (input [2] & 0xc0)> 6 );
Output [3] = input [2] & 0x3f;
Ctcopy = 4;
Switch (ctremaining ){
Case 1:
Ctcopy = 2;
Break;
Case 2:
Ctcopy = 3;
Break;
}
For (I = 0; I <ctcopy; I ++)
[Result appendstring: [nsstring stringwithformat:
@ "% C", base64encodingtable [Output [I];
For (I = ctcopy; I <4; I ++)
[Result appendstring:
@ "="];
Ixtext + = 3;
Charsonline + = 4;
If (length> 0) & (charsonline> = length ))
Charsonline = 0;
}
Return result;
}