Coding class
using System; namespace WebApplication1 {///
Public base64encoder (Byte [] INPUT; length = INPUT ;LENGTH = INPUT.LENGTH; IF ((Length% 3) == 0) {paddingcount = 0; blockcount = length / 3;} else {paddingcount = 3- (Length % 3); blockcount = (Length Paddingcount) / 3;} length2 = length paddingcount;
Public char [] getencoded () {byte [] Source2; Source2 = new byte [length2];
For (int x = 0; x Temp1 = (BYTE) ((B1 & 252) >> 2); Temp = (BYTE) ((B1 & 3) << 4); TEMP2 = (Byte) ((B2 & 240) >> 4); TEMP2 = Temp; Temp = (B2 & 15) << 2); temp3 = (Byte) ((B3 & 192) >> 6); TEMP3 = Temp; Temp4 = (BYTE) (B3 & 63); Buffer [x * 4] = temp1; buffer [x * 4 1] = TEMP2; BUFFER [x * 4 2] = TEMP3; BUFFER [x * 4 3] = TEMP4; } For (int x = 0; x Switch (Paddingcount) {Case 0: Break; Case 1: Result [Blockcount * 4-1] = '='; Break; Case 2: Result [blockcount * 4-1] = '='; Result [blockcount * 4- 2] = '='; Break; Default: Break;} Return Result;} Private char Sixbit2char (byte b) {char [] lookuptable = new char [64] {'a', 'b', 'c', ' D ',' 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 ',' 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 ',' ',' / '}; IF ((B> = 0) && (b <= 63)) {RETURN LOOKUPTABLE [(int) b];} else { Return '';}} } Decoding class Using system; Namespace WebApplication1 {/// Public Base64Decoder () {// // Todo: Add Constructor Logic //} here Public Base64Decoder (CHAR [] INPUT) {INT TEMP = 0; source = INPUT; length = INPUT.LENGTH FOR (INT x = 0; x <2; x ) {= {(INPUT [length-x-1] == ' = ') Temp ;} Paddingcount = Temp; blockcount = length / 4; length2 = blockcount * 3;} Public byte [] getDecoded () {byte [] buffer = new byte [length]; BYTE [] Buffer2 = new byte [length2]; For (int x = 0; x BYTE B, B1, B2, B3; BYTE TEMP1, TEMP2, TEMP3, TEMP4 For (int x = 0; x B = (byte) (Temp1 << 2); b1 = (byte) ((Temp2 & 48) >> 4); b1 = b; B = (Byte) ((Temp2 & 15) << 4); b2 = (byte) ((Temp3 & 60) >> 2); b2 = B; B = (Byte) ((Temp3 & 3) << 6); b3 = temp4; b3 = B; Buffer2 [x * 3] = B1; buffer2 [x * 3 1] = b2; buffer2 [x * 3 2] = b3;} Length3 = longth2-paddingcount; byte [] result = new byte [length3]; For (int x = 0; x Return Result;} Private byte char2sixbit (char c) {char [] lookuptable = new char [64] { 'A', 'b', 'c', 'd', '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', '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', ' ',' / '}; If (c ==' = ') Return 0; Else {for (int x = 0; x <64; x ) {if (Lookuptable [x] == c) Return (byte) x } Return 0;} } }