def captchaOCR(self, cUrl): #验证码识别接口,网上打码平台可以用100次,有时候识别不准 timestamp = str(int(time.time())) uid = '110588' #用户ID pdkey = '0MWzTrJX6BR90HxkYauc1BOjj1HMZ93L' #密钥 predict_type = '30400' img_data = requests.get(cUrl).content md5 = hashlib.md5() md5.update((timestamp + pdkey).encode()) csign = md5.hexdigest() md5 = hashlib.md5() md5.update((uid + timestamp + csign).encode()) csign = md5.hexdigest() # with open('abc.png','wb') as f: # f.write(img_data) data = { 'user_id': '110588', 'timestamp': timestamp, 'sign': csign, 'app_id': '', 'asign': '', 'predict_type': predict_type, 'up_type': 'mt' } file = {'img_data': ('img_data', img_data)} header = { 'User-Agent': 'Mozilla/5.0', } m = requests.post('http://pred.fateadm.com/api/capreg', data=data, headers=header, files=file) code = json.loads(m.text)['RspData'] code = json.loads(code) return code['result']
def md5(file=None): from hashlib import md5 if file: md5 = md5() for chunk in file.chunks(): md5.update(chunk) return md5.hexdigest()
def md5_for_file(fp, block_size=2**20): md5 = hashlib.md5() while True: data = fp.read(block_size) if not data: break md5.update(data) return md5.hexdigest()
def MD5endcoder(md5_str): from hashlib import md5 md5 = md5() data = md5_str + Salt md5.update(data.encode('utf-8')) result = md5.hexdigest() print(result) return result
def get_fptr_md5sum(fptr, block_size=2**20): """Processes a file md5sum 1MB at a time.""" md5 = hashlib.md5() while True: data = fptr.read(block_size) if not data: break md5.update(data) return md5.hexdigest()
def CalcSign(pd_id, passwd, timestamp): md5 = hashlib.md5() md5.update((timestamp + passwd).encode()) csign = md5.hexdigest() md5 = hashlib.md5() md5.update((pd_id + timestamp + csign).encode()) csign = md5.hexdigest() return csign
def get_hash(file_name) -> Tuple: BUF_SIZE = 65536 # ground to 65535 with open(file_name, "rb") as f: while True: data = f.read(BUF_SIZE) if not data: break md5.update(data) sha1.update(data) return (md5.hexdigest(), sha1.hexdigest())
def get_checksum(self, file_path): BUF_SIZE = 65536 md5 = hashlib.md5() with open(file_path, 'rb') as f: while True: data = f.read(BUF_SIZE) if not data: break md5.update(data) return md5.hexdigest()
def get_sig(post): params = [] for key,value in post.iteritems(): if key == 'sig': continue if key == 'headimg': continue params.append({'key': key, 'value': value}) params = sorted(params, key = lambda x: x['key']) md5 = hashlib.md5() string = u'&'.join(u'%s=%s'%(param['key'], param['value']) for param in params) string += u'&' + AireCheckConstant.API_SECRET_KEY #logger.warning(u"Signature Failed. string = %s" %(string)) md5.update(string.encode('utf-8')) return md5.hexdigest()
def getOneAttachMD5(attachment): try: from hashlib import md5 except ImportError: from md5 import md5 md5 = md5() try: f = open(attachment, 'rb') for chunk in iter(lambda: f.read(8192), ''): md5.update(chunk) return md5.hexdigest() except Exception, e: print str(e) sys.exit()
def _uuid(*args): """ uuid courtesy of Carl Free Jr: (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/213761) """ t = long(time.time() * 1000) r = long(random.random() * 100000000000000000L) try: a = socket.gethostbyname(socket.gethostname()) except: # if we can't get a network address, just imagine one a = random.random() * 100000000000000000L data = str(t) + ' ' + str(r) + ' ' + str(a) + ' ' + str(args) md5 = md5() md5.update(data) data = md5.hexdigest() return data
def _uuid( *args ): """ uuid courtesy of Carl Free Jr: (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/213761) """ t = long( time.time() * 1000 ) r = long( random.random() * 100000000000000000L ) try: a = socket.gethostbyname( socket.gethostname() ) except: # if we can't get a network address, just imagine one a = random.random() * 100000000000000000L data = str(t) + ' ' + str(r) + ' ' + str(a) + ' ' + str(args) md5 = md5() md5.update(data) data = md5.hexdigest() return data
if __name__ == "__main__": parser = OptionParser() parser.add_option("-f", "--comment-file", dest="commentFile") parser.add_option("-c", "--comment", dest="commentText") (options, args) = parser.parse_args() inputFile = args[0] outputFile = args[1] md5 = md5() sha1 = sha1() with open(inputFile, "rb") as inFile: for bytes in inFile: md5.update(bytes) sha1.update(bytes) comment = "" if options.commentText: if options.commentText != "--": comment = "<p>%s</p>" % options.commentText else: comment = "<p>%s</p>" % sys.stdin.read() elif options.commentFile: with open(options.commentFile, "r") as commentFile: commentLines = (line for line in commentFile if not line.lstrip().startswith("#")) # delete comments commentLines = itertools.imap(string.strip, commentLines) # remove redundant whitespace commentLines = itertools.ifilter(None, commentLines) # delete blank lines commentLines = (s[0].upper() + s[1:] for s in commentLines) # ensure first letter is capital
response = conn.getresponse() data=response.read() writeLog(data) headers = {"Content-type": "application/x-www-form-urlencoded", "Connection":"keep-alive"} if(__name__=='__main__'): #Please type in your username and password here username="******" #这是用户名 password="******" #这是密码 password="******"+password+"12345678" md5=md5() md5.update(password) md5password=md5.hexdigest()+"123456781" conn= httplib.HTTPConnection("gw.bupt.edu.cn") try: login(conn) print r'登录成功' except: print r'网络连接故障' ''' logout(conn) ''' conn.close()
#!/usr/bin/env python3 #- * -coding: utf - 8 - * - from hashlib import md5 md5 = md5() md5.update('how to use md5 1 in '.encode('utf-8')) md5.update('python hashlib?'.encode('utf-8')) print(md5.hexdigest())
def __md5_id(self, content): from hashlib import md5 md5 = md5() md5.update(content) return md5.hexdigest()
def md5optimal(a_file, block_size=65536): buf = a_file.read(block_size) while len(buf) > 0: md5.update(buf) buf = a_file.read(block_size) return md5.digest()
def md5_for_data(data): md5 = hashlib.md5() md5.update(data) return md5.hexdigest()
def CalcCardSign(cardid, cardkey, timestamp, passwd): md5 = hashlib.md5() md5.update(passwd + timestamp + cardid + cardkey) return md5.hexdigest()
from hashlib import md5 import requests from datetime import datetime openid = 'JH1257c5ded253ba1ba879147372437563' key = '2f6051d5f6eb807cfb82eb6d7da9ac08' phoneno = '18819451571' cardnum = '1' timestamp = datetime.now().strftime("%Y%m%d%H%M%S") orderid = timestamp + phoneno + cardnum #orderid = '26536256425' print(orderid) url = 'http://op.juhe.cn/ofpay/mobile/onlineorder' md5 = md5() md5.update((openid + key + phoneno + cardnum + orderid).encode('utf-8')) # 校验值,md5(OpenID+key+phoneno+cardnum+orderid),OpenID在个人中心查询 sign = md5.hexdigest() # phoneno=18819451571&cardnum=1&orderid=11111111&sign=eaac475a9fe89bf96e002b4d6e0cb025&key=2f6051d5f6eb807cfb82eb6d7da9ac08 data = { 'phoneno': phoneno, 'cardnum': cardnum, 'orderid': orderid, 'sign': sign, 'key': key } res = requests.post(url, data=data) res_json = res.json() print(res_json['error_code']) print(res_json['reason'])
from hashlib import md5 import sys if len(sys.argv) == 0 or "-h" in sys.argv: print("Usage: md5str <string>") else: md5 = md5() for arg in sys.argv: md5.update(arg) print md5.hexdigest()