Subversion Repositories SmartDukaan

Rev

Rev 17923 | Rev 18094 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17923 Rev 18092
Line 16... Line 16...
16
import socket
16
import socket
17
import time
17
import time
18
import urllib
18
import urllib
19
import urllib2
19
import urllib2
20
import urlparse
20
import urlparse
-
 
21
from Crypto.Hash import MD5
-
 
22
from Crypto.Cipher import DES
-
 
23
import string
21
#TODO Need to add messy stuff to conf.
24
#TODO Need to add messy stuff to conf.
22
 
25
 
23
 
26
 
24
SENDER = "cnc.center@shop2020.in"
27
SENDER = "cnc.center@shop2020.in"
25
PASSWORD = "5h0p2o2o"
28
PASSWORD = "5h0p2o2o"
26
SMTP_SERVER = "smtp.gmail.com"
29
SMTP_SERVER = "smtp.gmail.com"
27
SMTP_PORT = 587    
30
SMTP_PORT = 587    
28
 
31
 
-
 
32
_password = 'dtr18Feb2015'
-
 
33
_salt = '\xA9\x9B\xC8\x32\x56\x35\xE3\x03'
-
 
34
_iterations = 19
29
 
35
 
-
 
36
ALPHABET = string.ascii_uppercase + string.ascii_lowercase + \
-
 
37
           string.digits + '-_'
-
 
38
ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
-
 
39
BASE = len(ALPHABET)
-
 
40
SIGN_CHARACTER = '$'
30
 
41
 
31
con=None
42
con=None
32
headers = { 
43
headers = { 
33
            'User-agent':'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
44
            'User-agent':'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
34
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
45
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
Line 301... Line 312...
301
            finally:
312
            finally:
302
                pass
313
                pass
303
        except:
314
        except:
304
            "could not read"
315
            "could not read"
305
        return str1
316
        return str1
-
 
317
def encryptMessage(plaintext_to_encrypt1):
-
 
318
    hasher = MD5.new()
-
 
319
    hasher.update(_password)
-
 
320
    hasher.update(_salt)
-
 
321
    result = hasher.digest()
-
 
322
    for i in range(1, _iterations):
-
 
323
        hasher = MD5.new()
-
 
324
        hasher.update(result)
-
 
325
        result = hasher.digest()
-
 
326
 
-
 
327
    padding = 8 - len(plaintext_to_encrypt1) % 8
-
 
328
    plaintext_to_encrypt1 += chr(padding) * padding
-
 
329
    encoder = DES.new(result[:8], DES.MODE_CBC, result[8:16])
-
 
330
    encrypted = encoder.encrypt(plaintext_to_encrypt1)
-
 
331
    
-
 
332
    check1 =  encrypted.encode('base64')
-
 
333
    return check1
-
 
334
    
-
 
335
def decryptMessage(encryptedData):
-
 
336
    padding = 8 - len(encryptedData) % 8
-
 
337
    encryptedData += chr(padding) * padding
-
 
338
    hasher = MD5.new()
-
 
339
    hasher.update(_password)
-
 
340
    hasher.update(_salt)
-
 
341
    result = hasher.digest()
-
 
342
    for i in range(1, _iterations):
-
 
343
        hasher = MD5.new()
-
 
344
        hasher.update(result)
-
 
345
        result = hasher.digest()
-
 
346
     
-
 
347
    encoder2 = DES.new(result[:8], DES.MODE_CBC, result[8:16])
-
 
348
    decodeString =  encoder2.decrypt(encryptedData.decode('base64'))
-
 
349
    return ''.join(e for e in decodeString if e.isalnum() or e is '/' or e is ':' or e is ',' or e is '.')
-
 
350
 
-
 
351
def num_encode(n):
-
 
352
    if n < 0:
-
 
353
        return SIGN_CHARACTER + num_encode(-n)
-
 
354
    s = []
-
 
355
    while True:
-
 
356
        n, r = divmod(n, BASE)
-
 
357
        s.append(ALPHABET[r])
-
 
358
        if n == 0: break
-
 
359
    return ''.join(reversed(s))
-
 
360
 
-
 
361
def num_decode(s):
-
 
362
    if s[0] == SIGN_CHARACTER:
-
 
363
        return -num_decode(s[1:])
-
 
364
    n = 0
-
 
365
    for c in s:
-
 
366
        n = n * BASE + ALPHABET_REVERSE[c]
-
 
367
    return n