Need Help with Python/C API

2006-01-18 Thread pycraze
Hi guys,

I Need to know how do i create a dictionary... eg:
n = pali_hash
n={}
n={1:{ } }   ->  i need to know how to make a key of a dictionary, to a
dictionary using Python/C API's


Pls do help

-- 
http://mail.python.org/mailman/listinfo/python-list


why is my hash being weird??

2006-01-18 Thread pycraze
Hi  ,

   I am using Fedora Core -3  and my Python version is 2.4 .
   kernel version -  2.6.9-1.667smp
  There is some freakish thing that happens with python hashes when i
run a python script
  my python file is  basically :

  myhash = {}
  def summa():
global myhash
myhash[0] = 0
myhash[1] = 1
myhash[2] = 2
myhash[3] = 3

   i run a C file :
 main(int argc, char **argv)
 {
 int i = atoi(argv[1]), j;
printf("myhash = {}\n");
printf("def summa():\n");
printf("  global myhash\n");

for (j = 0; j < i; j++)
printf("myhash[%d] = %d\n", j, j);

 printf("\nsumma()\n");
   }

  and the output of this .c file is redirected to a  .py file.
  I do the following Steps to the .c file to create the  .py file

1 cc -o s s.c
2  ./s (input)  >>test.py
3  python test.py
When i run python to this .py file  , i find that this process eats
lots of virtual memory of my machine.  I can give u detailed examples
to what heights can the virtual memory can go  , when i do a top  ,
with the inputs given to the c file

  1.   input is 10 VIRT is 119m
  2.   input is 30 VIRT is 470m
  3input is 70 VIRT is 1098m
  4input is  100  VIRT is  1598m

 where  VIRT - virtual memory

  m  -  MB  ( Mega Bytes)

these results are very alarming as it means that each
hash[i] requires 1 KB of space approx .

I would like to know why and how to solve this problem ?

   I also did try change the above .c file , so that the new  .c file
will have multiple functions that divide the load of building the hash
structure. Then again the results are same

Pls do assist me with this problem of mine !!!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is my hash being weird??

2006-01-19 Thread pycraze
You are appending to the test file. How many times have
you appended to it? Once? Twice? A dozen times? Just
what is in the file test.py after all this time?

> when input =4
 >  ./s 4 >test.py
>
>test.py is
> myhash = {}
>  def summa():
>global myhash
>myhash[0] = 0
>   myhash[1] = 1
>myhash[2] = 2
>myhash[3] = 3
>
>if now input is 100 then  test py will be
>
>  myhash = {}
>  def summa():
>global myhash
>myhash[0] = 0
>myhash[1] = 1
>myhash[2] = 2
>myhash[3] = 3
>...
>...
>...
>...
>myhash[99] = 99

>  I append only once , and that too i do this exercise to get a largely big 
> hash.


This result came to a bit of a suprise..  when i construct large hashes
.. my system gets stalled

So i was interested how, for this i came up with this exercise .

Anyway thanks
Dennis

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is my hash being weird??

2006-01-19 Thread pycraze
Surely adopting the above method is much better than what i have
approached earlier . The main reason i did adopt this exercise was when
i have to marshal a 20 - 40 MB above test.py file to the disk , the
simple load of the test.py will sky rocket my virtual memory
consumption.

  I was bit troubled with this bottleneck , so i wanted to do some
research before i come to some conclusions .

Anyways , i really appreciate ur enthusiasm to helping me come to a
conclusion

Dennis

-- 
http://mail.python.org/mailman/listinfo/python-list


Segmentation Fault

2006-08-27 Thread pycraze
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ?  Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.

-- 
http://mail.python.org/mailman/listinfo/python-list


Apache with Python 2.4 Need Help !!!

2006-01-25 Thread pycraze
Hi,

  I am currently using Fedora Core - 3 with apache 2.0 Web Server and
Python 2.4 .

I have numerous dependencies when i want to use Python 2.4 version
with Apache 2.0 Web Server . I have installed the mod-python module ,
for apache , which is one of the package i got while installing Fedora
Core - 3 . I want to host some information onto another machine , which
have a running Apache 2.0 and mod-python installed too , so i would
like to know have apache released any version that can be successfully
use Python 2.4 ( with mod-python module ) using Fedora Core -3 .

   I would prefer a stable and successful version , if any , that goes
well with Python 2.4 .

-- 
http://mail.python.org/mailman/listinfo/python-list


Need Help

2007-07-10 Thread pycraze
Hi ,

  I need some info about the following snippet  .

---
  protocol = 'NTLMSSP\000'#name
type = '\001\000'   #type 1
zeros1 = '\000\000'

   zeros2 = '\000\000\000\000\000\000\000\000\000'
zeros3 = '\000\000\000\000\000\000\000\000\000\000\000'
smthg1 = '0\000\000\000\000\000\000\000'# something with
chr(48) length?
smthg2 = '0\000\000\000'# something with
chr(48) lenght?


  msg1 = protocol + type + zeros1 + flags + zeros2 + zeros3 +
smthg1 + smthg2
msg1 = base64.encodestring(msg1)
msg1 = string.replace(msg1, '\012', '')
---

   In the above code what does "
000\000\000\000\000\000\000\000\000 " signify ?  Which form of
representation is this ?

 This code is from the NTLM APS python code from sourceforge 0.98
version .

-- 
http://mail.python.org/mailman/listinfo/python-list


Need Help

2007-07-20 Thread pycraze
Hi ,

   I am currently working on NTLM (Windows NT Lan Manager) APS
(Authentication Proxy Server ) . NTLM is MS own proprietary protocol
that will allow successful authentication for only MS browsers .

  NTLM APS was successfully cracked by Rosmanov and i am working
on NTLM APS python package version 0.98 .  I am currently on it to
port to C language .

-- 
http://mail.python.org/mailman/listinfo/python-list


Need Help

2007-07-20 Thread pycraze
Hi ,

   I am currently working on NTLM (Windows NT Lan Manager) APS
(Authentication Proxy Server ) . NTLM is MS own proprietary protocol
that will allow successful authentication for only MS browsers .

  NTLM APS was successfully cracked by Rosmanov and i am working
on NTLM APS python package version 0.98 .  I am currently on it to
port to C language .

  I have a specific issue on the authentication technique which
this APS uses . NTLM APS python package ver 0.98 uses two major types
of authentication process

1) DES
2) MD4 .

 The author has clearly stated that he has adopted both the above
python implementations from Python Cryptology Toolkit ( py-crypto)
version 2.0.1 . I started to use the DES C implementation of py-crypto
so that i can have an equivalent DES python implementation without
breaking a sweat . ;-)

 But both the implementation was totally different . I am getting
different hashed outputs . I compared each byte value of password from
python DES implementation and C implementation , both were not same .

Is anyone out there, can tell me why they are different .
Also i found that the key generation is different between them and
i suspect because of this the outputs are different ? So can this be
that the C implementation of DES in py-crypto had bugs and that it had
been corrected by Rozmanov and implemented in python ?

Also will there be any difference in implementing DES b/w python
and C language ?

Thanks,

Dennis

-- 
http://mail.python.org/mailman/listinfo/python-list


NTLM APS python version 0.98

2007-07-20 Thread pycraze
Hi ,

 I am working on NTLM (Windows NT Lan Manager )APS
(Authentication Proxy Server ) , to port to C language .

I am using ethereal to monitor the packets sent between client and
server . NTLM is a MS proprietary protocol designed so that will allow
authentication only from MS browsers .

This  proprietary was cracked and code was written in python by
Rozmanov .

The link to the source pool about NTLM is

http://www.innovation.ch/personal/ronald/ntlm.html

 Have any one worked extensively with NTLM APS python package
0.98 ?

NTLM APS have a 6 step process :- (C) - client (S)- server

1: C  --> S   GET ...

2: C <--  S   401 Unauthorized
  WWW-Authenticate: NTLM

3: C  --> S   GET ...
  Authorization: NTLM 

4: C <--  S   401 Unauthorized
  WWW-Authenticate: NTLM 

5: C  --> S   GET ...
  Authorization: NTLM 

6: C <--  S   200 Ok


After step 6 client must connect to server . But when i run NTLM
APS and watch the packets sent b/w client and server  in ethereal , i
see that client does not recieve 200 Ok at Step 6 , but receives 401
Unauthorized . After this i get a dialog box which requests me to
enter my user name and password  .

I enter the credentials and then the server authorizes the
client .

I am sorry that i cannot give more info on this . I can send the
saved page log from ethereal . That will give a very good idea .

As per theory , it is only a 6 step process  . I am puzzled
regarding this .

thanks ,

dennis

-- 
http://mail.python.org/mailman/listinfo/python-list


Python C Embedded ! Attribute Error

2007-07-20 Thread pycraze
Hi ,

I am using the below C code so that i can embed a Python Code and
get input from a python function and use it in C code .

  Below is the C Code


#include 

int
main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue;
int i;

if (argc < 3) {
fprintf(stderr,"Usage: call pythonfile funcname [args]\n");
return 1;
}

Py_Initialize();
pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */

PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('/home/dennis/workplace/
aps098')");
PyRun_SimpleString("sys.path.append('/home/dennis/workplace/aps098/
lib')");
PyRun_SimpleString("import server, logger,config, ntlm_procs,
config_affairs ");
pModule = PyImport_Import(pName);
Py_DECREF(pName);

if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, argv[2]);
/* pFunc is a new reference */

if (pFunc && PyCallable_Check(pFunc)) {
pArgs = PyTuple_New(argc - 3);
for (i = 0; i < argc - 3; ++i) {
pValue = PyInt_FromLong(atoi(argv[i + 3]));
if (!pValue) {
Py_DECREF(pArgs);
Py_DECREF(pModule);
fprintf(stderr, "Cannot convert argument\n");
return 1;
   }
/* pValue reference stolen here: */
PyTuple_SetItem(pArgs, i, pValue);
}
pValue = PyObject_CallObject(pFunc, pArgs);
Py_DECREF(pArgs);
if (pValue != NULL) {
printf("Result of call: %ld\n", PyInt_AsLong(pValue));
Py_DECREF(pValue);
}
else {
Py_DECREF(pFunc);
Py_DECREF(pModule);
PyErr_Print();
fprintf(stderr,"Call failed\n");
return 1;
}
}
else {
if (PyErr_Occurred())
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
}
Py_XDECREF(pFunc);
Py_DECREF(pModule);
}
else {
PyErr_Print();
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
return 1;
}
Py_Finalize();
return 0;
}


   The python code is a simple code

def pr(var):
 print var

I am getting error

AttributeError: 'module' object has no attribute 'print'
Cannot find function "print"


  I am a newbie to python . I need some to embed python in C . Anyone
Pls help

-- 
http://mail.python.org/mailman/listinfo/python-list


Need Help with base64

2007-07-23 Thread pycraze
Hi ,

  I am currently trying to implement base64 encoding and decoding
scheme in C . Python has a module , base64 , that will  do the
encoding and decoding with ease . I am aware of OpenSSL having support
for base64 encoding and decoding , but i will have to now implement
both in C without using the openssl libraries .

I was able to download a code w.r.t. base 64 encoding and
decoding . I am attaching the code below .


void encodeblock( unsigned char cin[3], unsigned char cout[4], int
nlen )
{

cout[0] = cb64[ cin[0] >> 2 ];
cout[1] = cb64[ ((cin[0] & 0x03) << 4) | ((cin[1] & 0xf0) >> 4) ];
cout[2] = (unsigned char) (nlen > 1 ? cb64[ ((cin[1] & 0x0f) << 2)
| ((cin[2] & 0xc0) >> 6) ] : '=');
cout[3] = (unsigned char) (nlen > 2 ? cb64[ cin[2] & 0x3f ] :
'=');
}


void decodeblock( unsigned char cin[4], unsigned char cout[3] )
{
cout[ 0 ] = (unsigned char ) (cin[0] << 2 | cin[1] >> 4);
cout[ 1 ] = (unsigned char ) (cin[1] << 4 | cin[2] >> 2);
cout[ 2 ] = (unsigned char ) (((cin[2] << 6) & 0xc0) | cin[3]);
}


int base641_decodestring(char* pcstr,int size,char** ppcdest)
{
  unsigned char cin[4] = {""};
  unsigned char cout[3] = {""};
  unsigned char  cv = 0;
  int ni = 0;
  int nlen = 0;
  char* cptr = pcstr;
  *ppcdest = malloc(sizeof(char)*160);
  if (!*ppcdest)
{
return 1;
}
  memset(*ppcdest,0,sizeof(char)*160);

  char* pcstring = malloc( sizeof(char) * SIZE);
if (!pcstring)
  {
  aps_log("APS_log.txt","\nbae64.c:base64encode:malloc failed
\n");
  return 1;
  }
  memset(pcstring,'\0',SIZE);

for( nlen = 0, ni = 0; ni < 4; ni++ )
  {
cv = 0;
while(  cv == 0 )
  {
cv = (unsigned char) *cptr;
cv = (unsigned char) ((cv < 43 || cv > 122) ? 0 :
cd64[ cv - 43 ]);
if( cv )
{
cv = (unsigned char) ((cv == '$') ? 0 : cv - 61);
}
}
if( cptr++ )
  {
nlen++;
if( cv )
{
cin[ ni ] = (unsigned char) (cv - 1);
}
}
else
  {
cin[ni] = 0;
}
}
if( nlen )
  {
decodeblock( cin, cout );

}
  memcpy(*ppcdest,cout,160);
  return 0;
}/*end of base64_decode */

char* base64_encode(char* pcstr)
{
  unsigned char cin[3] = {""};
  unsigned char cout[4] = {""};
  int ni = 0;
  int nlen = 0;
  int flag = 1;
  char* cptr = pcstr;
  char* pcstring = malloc( sizeof(char) * SIZE);
if (!pcstring)
  {
  aps_log("APS_log.txt","\nbae64.c:base64encode:malloc failed
\n");
  return (void*)0;
  }
  memset(pcstring,'\0',SIZE);
  while( flag )
  {
for( ni = 0; ni < 3; ni++ )
{
  cin[ni] = (unsigned char)*cptr;
  if( *++cptr != '\0' )
nlen++;
  else
  {
cin[ni] = 0;
  flag = 0;
break;
  }
}
encodeblock(cin, cout,nlen);
strcat(pcstring,cout);
  }

  return pcstring;

}/* end of base64_encode */


  But this code gives different hex values as compared to the
python base64.encodestring and base64.decodestring respectively .

 I need some help on this matter . I need some pointers on
where is the mistake for the above file .

-- 
http://mail.python.org/mailman/listinfo/python-list