以下为JS代码 运行的正确结果为:E7CBEA22 http://s.web2.qq.com/api/get_user_friends2
<script type="text/javascript">
P = function (i, a) {
var r = [];
r[0] = i >> 24 & 255;
r[1] = i >> 16 & 255;
r[2] = i >> 8 & 255;
r[3] = i & 255;
for (var j = [], e = 0; e < a.length; ++e)
{
j.push(a.charCodeAt(e));
}
e = [];
for (e.push(new b(0, j.length - 1)); e.length > 0; )
{
var c = e.pop();
if (!(c.s >= c.e || c.s < 0 || c.e >= j.length))
{
if (c.s + 1 == c.e)
{
if (j[c.s] > j[c.e])
{
var l = j[c.s];
j[c.s] = j[c.e];
j[c.e] = l
}
}
else
{
for (var l = c.s, J = c.e, f = j[c.s]; c.s < c.e; )
{
for (; c.s < c.e && j[c.e] >= f; ) c.e--,
r[0] = r[0] + 3 & 255;
c.s < c.e && (j[c.s] = j[c.e], c.s++, r[1] = r[1] * 13 + 43 & 255);
for (; c.s < c.e && j[c.s] <= f; ) c.s++,
r[2] = r[2] - 3 & 255;
c.s < c.e && (j[c.e] = j[c.s], c.e--, r[3] = (r[0] ^ r[1] ^ r[2] ^ r[3] + 1) & 255)
}
j[c.s] = f;
e.push(new b(l, c.s - 1));
e.push(new b(c.s + 1, J))
}
}
}
j = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; e = "";
for (c = 0; c < r.length; c++) e += j[r[c] >> 4 & 15], e += j[r[c] & 15];
return e
}
b = function (b, i) {
this.s = b || 0;
this.e = i || 0
}
var v = P("1803940393", "73c92dd1c1bdfeed0fe3d95834c41ee3adf20e888c1e1046ceefd9c6d6e9071d");
alert(v);
</script>
已下为个人整理后的js代码
<script type="text/javascript">
P = function (i, a) {
var r = [];
r[0] = i >> 24 & 255;
r[1] = i >> 16 & 255;
r[2] = i >> 8 & 255;
r[3] = i & 255;
for (var j = [], e = 0; e < a.length; ++e) {
j.push(a.charCodeAt(e));
}
e = [];
for (e.push(new b(0, j.length - 1)); e.length > 0; ) {
var c = e.pop();
if (!(c.s >= c.e || c.s < 0 || c.e >= j.length)) {
if (c.s + 1 == c.e) {
if (j[c.s] > j[c.e]) {
var l = j[c.s];
j[c.s] = j[c.e];
j[c.e] = l
}
}
else {
var l = c.s, J = c.e, f = j[c.s];
for (; c.s < c.e; ) {
for (; c.s < c.e && j[c.e] >= f; ) {
c.e--;
r[0] = r[0] + 3 & 255;
}
if (c.s < c.e) {
j[c.s] = j[c.e];
c.s++;
r[1] = r[1] * 13 + 43 & 255;
}
for (; c.s < c.e && j[c.s] <= f; ) {
c.s++;
r[2] = r[2] - 3 & 255;
}
if (c.s < c.e) {
j[c.e] = j[c.s];
c.e--;
r[3] = (r[0] ^ r[1] ^ r[2] ^ r[3] + 1) & 255;
}
}
j[c.s] = f;
e.push(new b(l, c.s - 1));
e.push(new b(c.s + 1, J))
}
}
}
j = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; e = "";
for (c = 0; c < r.length; c++) e += j[r[c] >> 4 & 15], e += j[r[c] & 15];
return e
}
b = function (b, i) {
this.s = b || 0;
this.e = i || 0
}
var v = P("1803940393", "73c92dd1c1bdfeed0fe3d95834c41ee3adf20e888c1e1046ceefd9c6d6e9071d");
alert(v);
</script>
再下面为C#代码
public void GetHash(int i, string a)
{
int[] r = new int[4];
r[0] = i >> 24 & 255;
r[1] = i >> 16 & 255;
r[2] = i >> 8 & 255;
r[3] = i & 255;
//[0]: 107
//[1]: 133
//[2]: 242
//[3]: 41
List<int> j = new List<int>();
for (int x = 0; x < a.Length; ++x) j.Add((int)a[x]);
List<b> e = new List<b>();
for (e.Add(new b(0, j.Count - 1)); e.Count > 0; )
{
b c = e.Last();
e.Remove(c);
if (!(c.s >= c.e || c.s < 0 || c.e >= j.Count))
{
if (c.s + 1 == c.e)
{
if (j[c.s] > j[c.e])
{
var l = j[c.s];
j[c.s] = j[c.e];
j[c.e] = l;
}
}
else
{
int l = c.s, J = c.e, f = j[c.s];
for (; c.s < c.e; )
{
for (; c.s < c.e && j[c.e] >= f; )
{
c.e--;
r[0] = r[0] + 3 & 255;
}
if (c.s < c.e)
{
j[c.s] = j[c.e];
c.s++;
r[1] = r[1] * 13 + 43 & 255;
}
for (; c.s < c.e && j[c.s] <= f; )
{
c.s++;
r[2] = r[2] - 3 & 255;
}
if (c.s < c.e)
{
j[c.e] = j[c.s];
c.e--;
r[3] = (r[0] ^ r[1] ^ r[2] ^ r[3] + 1) & 255;
}
}
j[c.s] = f;
e.Add(new b(l, c.s - 1));
e.Add(new b(c.s + 1, J));
}
}
}
//[0]: 231
//[1]: 203
//[2]: 234
//[3]: 34
string[] jj = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
string ee = "";
for (int c = 0; c < r.Length; c++)
{
ee += jj[r[c] >> 4 & 15];
ee += jj[r[c] & 15];
}
//E7CBEA22
//E7CBEABC
string ss = "";
}
public class b
{
public int s { get; set; }
public int e { get; set; }
public b(int x, int y)
{
this.s = x;
this.e = y;
}
}