空间新算法
❶ 随机生成地图 空间分配算法
随机生成地图的空间分配算法主要包括以下几种常见方法:
网格划分法:
- 基本思想:将地图划分为固定大小的网格,每个网格可以视为一个独立的空间单元。
- 空间分配:随机决定每个网格的类型(如陆地、水域、森林等),或者根据一定的概率分布来分配空间类型。
- 优点:简单直观,易于实现。
- 缺点:生成的地图可能显得过于规整,缺乏自然感。
噪声函数法:
- 基本思想:利用噪声函数(如Perlin噪声)生成连续的噪声值,然后根据这些噪声值来分配空间类型。
- 空间分配:将噪声值映射到不同的空间类型上,例如,噪声值较高的区域可以是高山,较低的区域可以是平原。
- 优点:生成的地图具有自然感和随机性。
- 缺点:需要调整噪声函数的参数以获得满意的地图效果。
分形生成法:
- 基本思想:利用分形几何的原理,通过递归的方式生成具有自相似性的地图。
- 空间分配:在分形生成的过程中,根据分形结构的特性来分配空间类型。
- 优点:生成的地图具有复杂的细节和层次感。
- 缺点:计算复杂度较高,可能需要较长的生成时间。
元胞自动机法:
- 基本思想:使用元胞自动机模型,通过定义初始状态和规则来逐步生成地图。
- 空间分配:每个元胞根据当前状态和邻居元胞的状态来更新自己的状态,从而生成不同的空间类型。
- 优点:能够生成具有动态变化和复杂性的地图。
- 缺点:需要精心设计初始状态和规则以获得满意的地图效果。
在实际应用中,可以根据具体需求和场景选择合适的空间分配算法,或者结合多种算法来生成更加复杂和自然的地图。
❷ QQ空间登陆加密密码算法是什么
QQ空间现在采用的是动态加密,加密结果和验证码有密切关系,
也就是说是:密码+算法+验证码在一起,加密算法如下:
public static string smethod_0(string s)
{
MD5 mD = MD5.Create();
byte[] bytes = Encoding.ASCII.GetBytes(s);
byte[] array = mD.ComputeHash(bytes);
StringBuilder stringBuilder = new StringBuilder();
byte[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
byte b = array2[i];
stringBuilder.Append(b.ToString("x").PadLeft(2, '0'));
}
return stringBuilder.ToString().ToUpper();
}
public static byte[] EncyptMD5Bytes(string s)
{
MD5 mD = MD5.Create();
byte[] bytes = Encoding.ASCII.GetBytes(s);
return mD.ComputeHash(bytes);
}
public static string smethod_1(byte[] s)
{
MD5 mD = MD5.Create();
byte[] array = mD.ComputeHash(s);
StringBuilder stringBuilder = new StringBuilder();
byte[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
byte b = array2[i];
stringBuilder.Append(b.ToString("x").PadLeft(2, '0'));
}
return stringBuilder.ToString().ToUpper();
}
public static string EncryptQQWebMd5(string s)
{
MD5 mD = MD5.Create();
byte[] bytes = Encoding.ASCII.GetBytes(s);
byte[] array = mD.ComputeHash(bytes);
StringBuilder stringBuilder = new StringBuilder();
byte[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
byte b = array2[i];
stringBuilder.Append("\\x");
stringBuilder.Append(b.ToString("x2"));
}
return stringBuilder.ToString();
}
public static string EncryptOld(string password, string verifyCode)
{
return smethod_0(EncyptMD5_3_16(password) + verifyCode.ToUpper());
}
public static string Encrypt(string qq, string password, string verifyCode)
{
return Encrypt((long)Convert.ToDouble(qq), password, verifyCode);
}
public class ByteBuffer
{
private byte[] byte_0;
public Stream BaseStream;
public ByteBuffer()
{
this.BaseStream = new MemoryStream();
this.byte_0 = new byte[16];
}
public virtual long Seek(int offset, SeekOrigin origin)
{
return this.BaseStream.Seek((long)offset, origin);
}
public bool Peek()
{
return this.BaseStream.Position < this.BaseStream.Length;
}
public byte[] ToByteArray()
{
//long position = this.BaseStream.Position;
//this.BaseStream.Position = 0L;
//byte[] array = new byte[(int)((object)((IntPtr)this.BaseStream.Length))];
//this.BaseStream.Read(array, 0, array.Length);
//this.BaseStream.Position = position;
//return array;
long position = this.BaseStream.Position;
this.BaseStream.Position = 0L;
byte[] buffer = new byte[this.BaseStream.Length];
this.BaseStream.Read(buffer, 0, buffer.Length);
this.BaseStream.Position = position;
return buffer;
}
public void Put(bool value)
{
this.byte_0[0] = value ? ((byte)1) : ((byte)0);
this.BaseStream.Write(this.byte_0, 0, 1);
}
public void Put(byte value)
{
this.BaseStream.WriteByte(value);
}
public void Put(byte[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
this.BaseStream.Write(value, 0, value.Length);
}
public void PutInt(int value)
{
this.PutInt((uint)value);
}
public void PutInt(uint value)
{
this.byte_0[0] = (byte)(value >> 24);
this.byte_0[1] = (byte)(value >> 16);
this.byte_0[2] = (byte)(value >> 8);
this.byte_0[3] = (byte)value;
this.BaseStream.Write(this.byte_0, 0, 4);
}
public void PutInt(int index, uint value)
{
int offset = (int)this.BaseStream.Position;
this.Seek(index, SeekOrigin.Begin);
this.PutInt(value);
this.Seek(offset, SeekOrigin.Begin);
}
public byte Get()
{
return (byte)this.BaseStream.ReadByte();
}
}
public static string Encrypt(long qq, string password, string verifyCode)
{
ByteBuffer byteBuffer = new ByteBuffer();
byteBuffer.Put(EncyptMD5Bytes(password));
byteBuffer.PutInt(0);
byteBuffer.PutInt((uint)qq);
EncryptQQWebMd5(password);
byte[] s = byteBuffer.ToByteArray();
string str = smethod_1(s);
return smethod_0(str + verifyCode.ToUpper());
}
上面的加密算法,调用方法是:string str = Encrypt(QQ号, QQ密码, 验证码);
加密后的密码会返回到str中,然后使用返回的密码进行登录。
注:QQ空间登录是采用的GET而不是POST。