Bugsy , sorry for bumping this old thread , but i'm getting segmentation fault with C code! ( I try to run this in ubuntu 12.04 LTS )
Code:
#include <stdio.h>
#include <string.h>
void CryptString( char *szString , unsigned int iSize , const char *szKey )
{
if( !iSize )
return;
const char *szTmpKey = szKey;
while( iSize-- )
{
*szString = *szString++ ^ *szKey++;
if( !*szKey )
szKey = szTmpKey;
}
}
int main( int argc, char* args[] )
{
argc = 5;
if( ( argc - 1 ) == 4 )
{
args[0] = "hi bitches";
args[1] = "--key";
args[2] = "2";
args[3] = "--string";
args[4] = "1";
int iKey = 0 , iString = 0, i;
for( i = 0 ; i < 5; i++ )
{
if( iKey != 0 && iString != 0 )
break;
if ( strcmp(args[i], "--k") == 0 || strcmp(args[ i ], "-key") == 0)
{
iKey = i;
}
if ( strcmp(args[ i ],"--s") == 0 || strcmp(args[ i ],"--string") == 0)
{
iString = i;
}
}
if( iKey = 0 || iString == 0 )
{
printf( "No se encontraron los parámetros correspondientes\n" );
printf( "[ --k , -key ] - [ --s , -string ] \n" );
}
else
{
int ilen = strlen( args[ iString + 1 ] );
printf( "==========================\n" );
printf( "Key = %s\n" , args[ iKey + 2 ] );
printf( "Texto ingresado = -%s- \n", args[ iString + 1 ] );
CryptString( args[ iString + 1 ] , ilen, args[ iKey + 2 ] );
printf( "Texto saliente = -%s- \n" , args[ iString + 1 ] );
printf( "==========================\n" );
}
}
else
{
printf( "4 (Cuatro) parámetros requeridos! \n" );
printf( "[ --k , -key ] - [ --s , -string ] \n" );
}
}
__________________