encode base 64 in simply smtp client

F

fakessh

-----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-----
 
B

Barry Schwarz

-----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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top