Function UUDecode(strText) Const UU = "`!""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_" 'UU decoding takes a stream of input characters, each 'of which represents six bits, and reassembles a new stream 'comprised of eight bit words. The easiest way to decode it 'is to convert blocks of four 6-bit input words into blocks 'of three 8-bit output words. ' |ŻŻŻŻ||ŻŻŻŻ||ŻŻŻŻ||ŻŻŻŻ| ' 111111000000111111000000 ' |______||______||______| '32 is subtracted from each six-bit value before it is assembled. Unless 'the value is 96, in which case we subtract 64. Or you can just assume 'there is a 64-character substitution set and do it that way! 'Here are the 64 input characters which represent the 6-bit (0-63) words: ' `!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ ' 0---------1---------2---------3---------4---------5---------6--- 'A "`" represents "000000", "!" is "000001", and a "_" represents "111111" 'Because we will be processing four input words at a time, we must be sure 'our input is a multiple of four characters long. To make it interesting, 'every line starts with a DECODED length value. Which means we have to 'increase that length value by one third to get the encoded byte count in 'the line. Anything after the specified length is a checksum at the end of 'the line (which I'll ignore). Since a typical encoded line is 60 characters, 'that means it will decode to 45 characters. Because the decode process 'subtracts 32, the encoder adds 32 to the count, making it 77. The character 'whose decimal value is 77 is an uppercase "M". Which is why most UU lines 'start with an M! Dim strIn, strOut, strBuffer, strChar Dim lngLength, lngCount Dim intIn1, intIn2, intIn3, intIn4 Dim intOut1, intOut2, intOut3 Dim strOut1, strOut2, strOut3 strIn = strText 'Don't modify the input (I don't like to use ByVal) 'Strip the beginning and end If InStr(strIn, "begin") <> 0 Then strIn = Mid(strIn, InStr(strIn, "begin")) strIn = Mid(strIn, InStr(strIn, vbCrLf) + 2) End If If InStr(strIn, "end") <> 0 Then strIn = Left(strIn, InStr(strIn, "end") - 3) End If 'Remove the line counts and unwrap the data strBuffer = "" Do lngLength = InStr(UU, Left(strIn, 1)) - 1 lngLength = Int(.9 + lngLength + lngLength / 3) If lngLength = 0 Then 'Bail out when zero-length line is hit (the end) strIn = "" Exit Do End If strIn = Mid(strIn, 2) strBuffer = strBuffer & Left(strIn, lngLength) If InStr(strIn, vbCrLf) <> 0 Then strIn = Mid(strIn, InStr(strIn, vbCrLf) + 2) Loop Until InStr(strIn, vbCrLf) = 0 strBuffer = strBuffer & strIn strIn = strBuffer 'Pad with an illegal character to make it a multiple of 4 characters long lngLength = Len(strIn) Do While Len(strIn) Mod 4 <> 0 strIn = strIn & " " Loop 'Process blocks of four input characters For lngCount = 1 To lngLength Step 4 'Get the four six-bit values intIn1 = InStr(UU, Mid(strIn, lngCount, 1)) - 1 intIn2 = InStr(UU, Mid(strIn, lngCount + 1, 1)) - 1 intIn3 = InStr(UU, Mid(strIn, lngCount + 2, 1)) - 1 intIn4 = InStr(UU, Mid(strIn, lngCount + 3, 1)) - 1 'Note that if we hit our illegal pad character above, we will return a -1 intOut1 = intIn1 * 4 'the entire first input If intIn2 <> -1 Then intOut1 = intOut1 + (intIn2 \ 16) 'the upper two bits of the second input End If strOut1 = Chr(intOut1) 'The second output is the lower 4 bits of the second input and upper 4 bits of the third If intIn2 <> -1 Then intOut2 = (intIn2 And 15) * 16 'lower 4 bits of the second input If intIn3 <> -1 Then intOut2 = intOut2 + (intIn3 \ 4) 'upper 4 bits of the third input End If strOut2 = Chr(intOut2) Else strOut2 = "" End If 'The third output is the lower two bits of the third input and all the fourth If intIn3 <> -1 Then intOut3 = (intIn3 And 3) * 64 If intIn4 <> -1 Then intOut3 = intOut3 + intIn4 'all the fourth End If strOut3 = Chr(intOut3) Else strOut3 = "" End If 'Append the three characters to the output strOut = strOut & strOut1 & strOut2 & strOut3 Next 'Remove any trailing binary zeros Do While Right(strOut, 1) = Chr(0) strOut = Left(strOut, Len(strOut) - 1) Loop 'Return the output UUDecode = strOut End Function