Skip to content

Instantly share code, notes, and snippets.

@ibigbug
Last active December 31, 2015 10:29
Show Gist options
  • Save ibigbug/7973457 to your computer and use it in GitHub Desktop.
Save ibigbug/7973457 to your computer and use it in GitHub Desktop.
A encryption
var crypto = require('crypto');
function CodeUserName(name) {
var md5 = crypto.createHash('md5');
var time = Math.floor((new Date()).getTime() / 1000);
time = 1387112383;
var timediv5 = Math.floor(time / 5);
var timestr = "";
for (var i = 0; i != 4; ++i) {
timestr += String.fromCharCode((timediv5 >> ((3 - i) * 8)) % 256);
}
var data = timestr;
data += name.substr(0, 12);
data += "zjxinlisx01";
//var aftermd5 = hex_md5(data);
var aftermd5 = md5.update(data).digest('hex');
var sig = aftermd5.substring(0, 2);
var temp = new Array(32);
var timechar = new Array(4);
for (i = 0; i != 4; ++i) timechar[i] = timestr.charCodeAt(i);
for (i = 0; i < 32; i++) {
temp[i] = timechar[(31 - i) >> 3] & 1;
timechar[(31 - i) >> 3] = timechar[(31 - i) >> 3] >> 1;
}
var timeHash = new Array(4);
for (i = 0; i < 4; i++) {
timeHash[i] = temp[i] * 128 + temp[4 + i] * 64 + temp[8 + i] * 32 + temp[12 + i] * 16 + temp[16 + i] * 8 + temp[20 + i] * 4 + temp[24 + i] * 2 + temp[28 + i];
}
temp[1] = (timeHash[0] & 3) << 4;
temp[0] = (timeHash[0] >> 2) & 0x3F;
temp[2] = (timeHash[1] & 0xF) << 2;
temp[1] = (timeHash[1] >> 4 & 0xF) + temp[1];
temp[3] = timeHash[2] & 0x3F;
temp[2] = ((timeHash[2] >> 6) & 0x3) + temp[2];
temp[5] = (timeHash[3] & 3) << 4;
temp[4] = (timeHash[3] >> 2) & 0x3F;
var sig2 = "";
for (i = 0; i < 6; i++) {
var tp = temp[i] + 0x020;
if (tp >= 0x40) {
tp++;
}
sig2 += String.fromCharCode(tp);
}
return "\r\n" + sig2 + sig + name;
}
if (module.id == '.') {
console.log(CodeUserName('13333333333'));
}
from __future__ import print_function
import time
import hashlib
def CodeUserName(name):
_time = int(time.time())
_time = 1387112383
timediv5 = int(_time / 5)
timestr = ''
for i in range(0, 4):
timestr += unichr((timediv5 >> ((3 - i) * 8)) % 256)
data = timestr
data += name[0:12]
data += 'zjxinlisx01'
aftermd5 = hashlib.md5(data.encode('utf-8')).hexdigest()
sig = aftermd5[0:2]
temp = [None] * 32
timechar = [None] * 4
for i in range(0, 4):
timechar[i] = ord(timestr[i])
for i in range(0, 32):
temp[i] = timechar[(31 - i) >> 3] & 1
timechar[(31 - i) >> 3] = timechar[(31 - i) >> 3] >> 1
timeHash = [None] * 4
for i in range(0, 4):
timeHash[i] = temp[i] * 128 + temp[4 + i] * 64 + temp[8 + i] * 32 + temp[12 + i] * 16 + temp[16 + i] * 8 + temp[20 + i] * 4 + temp[24 + i] * 2 + temp[28 + i]
temp[1] = (timeHash[0] & 3) << 4
temp[0] = (timeHash[0] >> 2) & 0x3F
temp[2] = (timeHash[1] & 0xF) << 2
temp[1] = (timeHash[1] >> 4 & 0xF) + temp[1]
temp[3] = timeHash[2] & 0x3F
temp[2] = ((timeHash[2] >> 6) & 0x3) + temp[2]
temp[5] = (timeHash[3] & 3) << 4
temp[4] = (timeHash[3] >> 2) & 0x3F
sig2 = ''
for i in range(0, 6):
tp = temp[i] + 0x020
if tp >= 0x40:
tp += 1
sig2 += unichr(tp)
return '\r\n' + sig2 + sig + name
if __name__ == '__main__':
print(CodeUserName('13333333333'))
@fengmk2
Copy link

fengmk2 commented Dec 16, 2013

对比一下 python和js的 "(timediv5 >> ((3 - i) * 8)) % 256" 结果吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment