?? guidcalculationtest.java
字號:
package preverification.inputs;
public class GUIDCalculationTest
{
public class GUIDCalculationTestData
{
public GUIDCalculationTestData()
{
}
public void update(byte[] newbuf, int bufstart, int buflen)
{
}
public void md5final(byte[] digest)
{
}
}
private String guid;
public void constructGUID(String template, String version)
{
// use MD5 as a scrambling function
GUIDCalculationTestData digester = new GUIDCalculationTestData();
byte[] digest = new byte[16];
String value = System.getProperty("microedition.platform");
if (value != null)
{
byte[] array = value.getBytes();
digester.update(array, 0, array.length);
}
if (template != null)
{
byte[] array = template.getBytes();
digester.update(array, 0, array.length);
}
if (version != null)
{
byte[] array = version.getBytes();
digester.update(array, 0, array.length);
}
long theTime = System.currentTimeMillis();
int i;
for (i = 0; i < 8; i++)
{
digest[i] = (byte)theTime;
theTime >>= 8;
}
digester.update(digest, 0, 8);
// extract the 128 bit digest and "fold" to a 64 bit string
digester.md5final(digest);
for (i = 0; i < 8; i++)
{
digest[i] ^= digest[i+8];
}
// append 16 bits of checksum to make an 80 bit string
int sum1 = 0;
int sum2 = 0;
for (i = 0; i < 8; i++)
{
int theByte = (int) digest[i] & 0xFF;
sum1 += theByte;
sum2 += sum1;
}
sum1 %= 255;
sum2 %= 255;
int out1 = ((255 * 2 - sum1 - sum2) % 255);
int out2 = ((255 * 2 - sum1 - out1) % 255);
digest[8] = (byte) out1;
digest[9] = (byte) out2;
// reduce into a 16-char string using base 32
StringBuffer buf = new StringBuffer(16);
buf.append(GUID_CHARS.charAt( (((int)digest[0] & 0xF8) >> 3) ));
buf.append(GUID_CHARS.charAt( (((int)digest[0] & 0x07) << 2) | (((int)digest[1] & 0xC0) >> 6) ));
buf.append(GUID_CHARS.charAt( (((int)digest[1] & 0x3E) >> 1) ));
buf.append(GUID_CHARS.charAt( (((int)digest[1] & 0x01) << 4) | (((int)digest[2] & 0xF0) >> 4) ));
buf.append(GUID_CHARS.charAt( (((int)digest[2] & 0x0F) << 1) | (((int)digest[3] & 0x80) >> 7) ));
buf.append(GUID_CHARS.charAt( (((int)digest[3] & 0x7C) >> 2) ));
buf.append(GUID_CHARS.charAt( (((int)digest[3] & 0x03) << 3) | (((int)digest[4] & 0xE0) >> 5) ));
buf.append(GUID_CHARS.charAt( (((int)digest[4] & 0x1F) ) ));
buf.append(GUID_CHARS.charAt( (((int)digest[5] & 0xF8) >> 3) ));
buf.append(GUID_CHARS.charAt( (((int)digest[5] & 0x07) << 2) | (((int)digest[6] & 0xC0) >> 6) ));
buf.append(GUID_CHARS.charAt( (((int)digest[6] & 0x3E) >> 1) ));
buf.append(GUID_CHARS.charAt( (((int)digest[6] & 0x01) << 4) | (((int)digest[7] & 0xF0) >> 4) ));
buf.append(GUID_CHARS.charAt( (((int)digest[7] & 0x0F) << 1) | (((int)digest[8] & 0x80) >> 7) ));
buf.append(GUID_CHARS.charAt( (((int)digest[8] & 0x7C) >> 2) ));
buf.append(GUID_CHARS.charAt( (((int)digest[8] & 0x03) << 3) | (((int)digest[9] & 0xE0) >> 5) ));
buf.append(GUID_CHARS.charAt( (((int)digest[9] & 0x1F) ) ));
this.guid = buf.toString();
}
private static final String GUID_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -