encode base 64 in simply smtp client

Discussion in 'C Programming' started by fakessh, May 1, 2012.

  1. fakessh

    fakessh Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    hello hello honorable Member Doctor

    i work on small projet
    https://github.com/fakessh/openprojectssl/blob/master/smtp.c
    https://github.com/fakessh/openprojectssl/blob/master/smtp.h


    i realise encode base 64 like that

    //realizing base64
    void base64(char *dbuf, char *buf128, int len)
    {
    struct data6 *ddd = NULL;
    int i = 0;
    char buf[256] = {0};
    char *tmp = NULL;
    char cc = '\0';
    memset(buf, 0, 256);
    strcpy(buf, buf128);
    for(i = 1; i <= len/3; i++)
    {
    tmp = buf+(i-1)*3;
    cc = tmp[2];
    tmp[2] = tmp[0];
    tmp[0] = cc;
    ddd = (struct data6 *)tmp;
    dbuf[(i-1)*4+0] = con628((unsigned int)ddd->d1);
    dbuf[(i-1)*4+1] = con628((unsigned int)ddd->d2);
    dbuf[(i-1)*4+2] = con628((unsigned int)ddd->d3);
    dbuf[(i-1)*4+3] = con628((unsigned int)ddd->d4);
    }
    if(len%3 == 1)
    {
    tmp = buf+(i-1)*3;
    cc = tmp[2];
    tmp[2] = tmp[0];
    tmp[0] = cc;
    ddd = (struct data6 *)tmp;
    dbuf[(i-1)*4+0] = con628((unsigned int)ddd->d1);
    dbuf[(i-1)*4+1] = con628((unsigned int)ddd->d2);
    dbuf[(i-1)*4+2] = '=';
    dbuf[(i-1)*4+3] = '=';
    }
    if(len%3 == 2)
    {
    tmp = buf+(i-1)*3;
    cc = tmp[2];
    tmp[2] = tmp[0];
    tmp[0] = cc;
    ddd = (struct data6 *)tmp;
    dbuf[(i-1)*4+0] = con628((unsigned int)ddd->d1);
    dbuf[(i-1)*4+1] = con628((unsigned int)ddd->d2);
    dbuf[(i-1)*4+2] = con628((unsigned int)ddd->d3);
    dbuf[(i-1)*4+3] = '=';
    }
    return;
    }


    char con628(char c6)
    {
    char rtn = '\0';
    if (c6 < 26) rtn = c6 + 65;
    else if (c6 < 52) rtn = c6 + 71;
    else if (c6 < 62) rtn = c6 - 4;
    else if (c6 == 62) rtn = 43;
    else rtn = 47;
    return rtn;
    }


    one might think that incidentally changed all "char" by "unsigned
    char ", it would avoid the casts for arithmetic (yes, it takes a blow
    casts for "") but it is less boring than the errors
    undetectable from negative char!

    another way to make this challenge would be to consider a code like this
    but I do not know how
    I have long bothered to look at my code

    and i think this code is a cool for use

    I ask your humble opinion with the advice and example that go

    sincerely
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.14 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iEYEARECAAYFAk+gVeUACgkQNgqL0sJiZ0KL8wCgrYXY5RDcC/8MwIZ3W8B2jCxF
    ThcAnivQ0D5rXrxhwou6oqZPNtKiSXcN
    =wn07
    -----END PGP SIGNATURE-----
     
    fakessh, May 1, 2012
    #1
    1. Advertising

  2. On Tue, 01 May 2012 23:30:13 +0200, fakessh <>
    wrote:

    >-----BEGIN PGP SIGNED MESSAGE-----
    >Hash: SHA1
    >
    >hello hello honorable Member Doctor
    >
    >i work on small projet
    >https://github.com/fakessh/openprojectssl/blob/master/smtp.c
    >https://github.com/fakessh/openprojectssl/blob/master/smtp.h


    This header file is an abomination. It creates typedefs for some
    signed types that start with u_, thereby misleading the reader into
    thinking they are unsigned types.

    >
    >
    >i realise encode base 64 like that
    >
    >//realizing base64
    >void base64(char *dbuf, char *buf128, int len)
    >{
    > struct data6 *ddd = NULL;
    > int i = 0;
    > char buf[256] = {0};
    > char *tmp = NULL;
    > char cc = '\0';
    > memset(buf, 0, 256);


    Since you initialized buf to 0, this does nothing.

    > strcpy(buf, buf128);
    > for(i = 1; i <= len/3; i++)
    > {
    > tmp = buf+(i-1)*3;
    > cc = tmp[2];
    > tmp[2] = tmp[0];
    > tmp[0] = cc;
    > ddd = (struct data6 *)tmp;


    struct data6 consists of several unsigned int. It most likely
    requires alignment on a multiple of 4. tmp is incremented in steps of
    3. It is guaranteed that this will not produce a valid value in one
    of the first two iterations of the for loop.

    > dbuf[(i-1)*4+0] = con628((unsigned int)ddd->d1);


    d1 is already defined as an unsigned int. What purpose do you think
    the cast serves?

    con628 is expecting a char. Why are you passing it an unsigned int?

    > dbuf[(i-1)*4+1] = con628((unsigned int)ddd->d2);
    > dbuf[(i-1)*4+2] = con628((unsigned int)ddd->d3);
    > dbuf[(i-1)*4+3] = con628((unsigned int)ddd->d4);
    > }
    > if(len%3 == 1)
    > {
    > tmp = buf+(i-1)*3;
    > cc = tmp[2];
    > tmp[2] = tmp[0];
    > tmp[0] = cc;
    > ddd = (struct data6 *)tmp;
    > dbuf[(i-1)*4+0] = con628((unsigned int)ddd->d1);
    > dbuf[(i-1)*4+1] = con628((unsigned int)ddd->d2);
    > dbuf[(i-1)*4+2] = '=';
    > dbuf[(i-1)*4+3] = '=';
    > }
    > if(len%3 == 2)
    > {
    > tmp = buf+(i-1)*3;
    > cc = tmp[2];
    > tmp[2] = tmp[0];
    > tmp[0] = cc;
    > ddd = (struct data6 *)tmp;
    > dbuf[(i-1)*4+0] = con628((unsigned int)ddd->d1);
    > dbuf[(i-1)*4+1] = con628((unsigned int)ddd->d2);
    > dbuf[(i-1)*4+2] = con628((unsigned int)ddd->d3);
    > dbuf[(i-1)*4+3] = '=';
    > }
    > return;
    >}
    >
    >
    >char con628(char c6)
    >{
    > char rtn = '\0';
    > if (c6 < 26) rtn = c6 + 65;
    > else if (c6 < 52) rtn = c6 + 71;
    > else if (c6 < 62) rtn = c6 - 4;
    > else if (c6 == 62) rtn = 43;
    > else rtn = 47;
    > return rtn;
    >}
    >
    >
    >one might think that incidentally changed all "char" by "unsigned
    >char ", it would avoid the casts for arithmetic (yes, it takes a blow


    Since your casts serve no purpose, I don't know what point you are
    trying to make here.

    >casts for "") but it is less boring than the errors
    >undetectable from negative char!
    >
    >another way to make this challenge would be to consider a code like this
    >but I do not know how
    >I have long bothered to look at my code
    >
    >and i think this code is a cool for use
    >
    >I ask your humble opinion with the advice and example that go


    --
    Remove del for email
     
    Barry Schwarz, May 2, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,092
    Roedy Green
    Jan 24, 2006
  2. Alex Hunsley
    Replies:
    4
    Views:
    3,489
    Tim Williams (gmail)
    Jun 29, 2004
  3. Raaijmakers, Vincent \(GE Infrastructure\)

    RE: sending of mail (smtp) - connection refused - but smtp serveris running!

    Raaijmakers, Vincent \(GE Infrastructure\), Jun 29, 2004, in forum: Python
    Replies:
    0
    Views:
    888
    Raaijmakers, Vincent \(GE Infrastructure\)
    Jun 29, 2004
  4. Copelandia Cyanescens

    smtplib.SMTP "no attributes SMTP"

    Copelandia Cyanescens, Jul 31, 2004, in forum: Python
    Replies:
    2
    Views:
    1,440
    Copelandia Cyanescens
    Jul 31, 2004
  5. tshad
    Replies:
    1
    Views:
    895
    bruce barker
    May 5, 2008
Loading...

Share This Page