C# .NET - uudecode

Asked By Vaibhav Sehgal
14-Nov-02 04:59 AM
I'm writing my own decoder for uuencoding and need help with the following :
In all uu en/decoding code in C/C++/VC++ a en/decoding algorithim called ENC or DEC is used which is as follows

#define ENC(c) ((c) ? ((c) & 077) + ' ': '`')
#define DEC(c)  (((c) - ' ') & 077)

c is a char and this returns int

I need the DEC functionality in C# ... any help (any c gurus around).

Note: I am using this function in C# but it returns a wrong value.

private int DEC(char c)
{
  return ((c) - ' ') & 077;
}

If you post the entire C++ class  If you post the entire C++ class

14-Nov-02 06:19 PM
I'll decompile or whatever and see if I can translate into C#.
There is a System.Web.Mail.Attachment encoding in .NET one
of the choices is UUEncoded
but I couldn't find the code for the actual codec. Unfortunately
the attachment class has no available methods to convert the
attachment object to a string.

c code for uudecode  c code for uudecode

15-Nov-02 01:16 AM
Hi Peter,

This is the C code for uudecode. I have implemented everything in C# including the bitwise operators etc... everything works fine except the DEC functionality.In VC++ this code works perfectly.
Example : for c= 'M' ascii-77 the DEC function in C returns 45 but the C# function returns 13.
Ignore the readline function coz I use a streamreader and read line by line from the file. Also ignore the checking for begin and end coz we remove these lines in our uuencoded files.
The main decoding begins at n = DEC (*p); till the end of function.

Any help will be appreciated...

#include <stdio.h>
#include <string.h>
#define DEC(c)  (((c) - ' ') & 077)
static char outname[200];
int ReadDataLine(FILE *f,char *buf)
{
        int c,i;

        i=0;
        while ((c=fgetc(f)) != EOF) {
                if (c == '\n') break;
                if (c != '\r') {
                        buf[i++] = c;
                }
        }
        buf[i] = 0;
        return(c == EOF ? 0 : 1);
}

static char *uudecode (FILE *f)
{
  register int n;
  register char ch, *p;
  char buf[2 * BUFSIZ];
  FILE *out;

  do {
          if (!ReadDataLine(f,buf)) return(NULL);
  }
  while (strncmp(buf,"begin",5));
  p = buf + 6;
  while (*p && (*p == ' '|| *p == '0' || *p == '6')) p++; 
  strcpy(outname,p);
  /* Create output file and set mode.  */ 
  out = fopen(outname,"wb");
  /* For each input line:  */
  while (1)
    {
        if (!ReadDataLine(f,buf)) break;
        if (!strncmp(buf,"end\r\n",5)) break;
          p = buf;

      /* N is used to avoid writing out all the characters at the end of
         the file.  */

      n = DEC (*p);
      if (n <= 0)
        break;
      for (++p; n > 0; p += 4, n -= 3)
        {
          if (n >= 3)
            {
              ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4; 
              fputc(ch,out);
              ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2; 
              fputc (ch,out);
              ch = DEC (p[2]) << 6 | DEC (p[3]);
              fputc (ch,out);
            }
          else
            {
              if (n >= 1)
                {
                  ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4; 
                  fputc (ch,out);
                }
              if (n >= 2)
                {
                  ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2; 
                  fputc (ch,out);
                }
            }
        }
    }

  fclose(out);
  return outname;
}

int main(int argc,char *argv[])
{
        FILE *f;

        if (argc <= 1) {
                printf("Usage: %s <input file>\n",argv[0]); 
                return(1);
        }
        f = fopen(argv[1],"rb");
        if (f == NULL) {
                printf("I can't find %s\n",argv[1]); 
                return(1);
        }
        uudecode(f);
        fclose(f);
        printf("Result decoded in %s\n",outname); 
        return(0);
}

Try this:  Try this:

15-Nov-02 10:03 AM
string s = "M";

int dec =(int)s[0];
Response.Write(dec.ToString());
Here is something!  Here is something!
05-Jan-07 08:02 PM
I found some old VB code for uuEncode and uuDecode on strings and ported it to VB.NET. Then I decompiled it into C# and ported it to C#. The C# implementation uses the VB.NET compatiblity layer for the string methods, but it works fine. The whole solution with a Winforms test harness, the VB.NET class library, and the C# class library, can be downloaded here: <A href="/articles/20021115.zip">http://www.eggheadcafe.com/articles/20021115.zip</A>
kewl !!!  kewl !!!
20-Nov-02 10:02 AM
Yup, we did the same thing...
we got some VB 6 code on the net and converted it to C#, but the string manipulation for the algorithm was erroneous in C# so we too included the vb runtime to do the MID,ASC and CHR functions.
It seems to be working pretty well..... but cant it be done in C# ONLY.....
I really dont believe that VB handles datatypes better than C# ?????
Hello Iam unable get this code  Hello Iam unable get this code
27-Jan-09 02:14 AM

Please could you send me the C# code where i need to extract for my web application.

i have .eml file which contains text body as email contents & with attachment in pdf

Begin 666 12121.pdf

*******Unrecongized characters ******

end]

 

i need to decode this by passing to uudecode() function .. please help me resolving this issue :)

 

 

-PrashanthSpark

Create New Account
help
VB.NET Random System.StackOverflowException Error Hello everybody, I'm a newbie in VB.NET dev. I get a code from a app and i would to test it alone password As New Password password.EncryptedPassword = "2945D7F0F653C2EDFF" password.keyindex = 154 password.getPassword() End Sub Public Class Password ' Keyarray, where the Xor-Keys are stored (To compile, use 0 to 999, for at which position we are. intXorValueHex = CInt ( "&H" & Mid(Hex, pwPosition * 2 - 1, 2)) intXorValueKey = Asc(Mid(Key, pwPosition, 1)) 'XOR this characters against eachother TempInt = (intXorValueHex Xor intXorValueKey) 'Write the Function which returns the Password as string Return Me .dec(EncryptedPassword, keyindex) End Function End Class End Module Thanks for your help Best Regards Samuel ps: i forget to say that
StreamWriter problem .NET Framework I am using VB.NET 2005 and streamWriter to write to a file. Before writing to the file, I encrypt Dim strTempChar As String Dim I As Int16 For I = 1 To Len(Text) strTempChar = Asc(Mid$(Text, I, 1)) + {some number} Mid$(Text, I, 1) = Chr(strTempChar) Next I Crypt = Text VB.NET Discussions StreamWriter (1) VB.NET (1) VB (1) Encoding (1) Print (1) SwFile.Write (1) SwFile.Close (1) StrTempChar (1 application you are using to view the file assumes or expects another encoding. The 'StreamWriter' class' constructor is overloaded- --one overload expects a 'System.Text.Encoding' object. - - M S Herfried K
c# vs VB.net I wrote a VB.Net program that did a lot of string handling and basically mocked a spreadsheet in a write code like this: string sql = @"SELECT * FROM SomeSuchTable WHERE ID = 'WhatHaveYou' ORDER BY ThisAndThatField ASC "; So when someone hands you a SQL statement you can just paste it into your code and the output (i.e. carriage returns) will still keep the format. In VB NET, you would have to write the following to keep the formatting. dim sql as string SELECT *" & vbCrLf sql + = "FROM SomeSuchTable" & vbCrLf sql + = "WHERE ID = 'WhatHaveYou'" & vbCrLf sql + = "ORDER BY ThisAndThatField ASC " And that's annoying. • Increments / Decrements . a++;a- -; 'Nuff said • Money . No, not the data
C# equivelant of VB.NET's Asc() .NET Framework VB.NET has a function, Asc(), that gets the Ascii value of a character. I am attempting to find an equivelant IsLittleEndian (1) Encoding.Default.GetBytes (1) FileIOEncoding.IsSingleByte (1) (int)c Arne PS: I believe Asc is a VB6'ism. Asc() can still be used VB.Net. It was in VB3-VB6 and QuickBasic too. Mr
C# or VB.NET? .NET Framework Hi, I am a beginner in .NET. I have been coding in plain asp before, using VBScript, and now when i'm migrating to .NET, i obviously chosed VB.NET. But. . . . when i see code samples on net, they are mostly in C#, i also newsgroup where someone mentioned that it was a very "heated topic back in 2002 about VB.NET vs C#". So, my question is. . . what was the result of that topic? What is best to go for, VB.NET or C#? and why? Thanks and regards ASP.NET Discussions SdnelhBqAEpRranZ2dnUVZ8qugnZ2d (1) IFormatProvider (1) Office