VB:
Public Function EncryptionPassword(aPassword As String) As String Const EncryptTbl = "H5OPBWI7F6ZJX1T2G8ELQ9ARCVDY4K3SN0UM"
Dim EncryptTimes As Long
Dim EncryptNums As Long
Dim tmpKey As String
Dim tmpChar As String
Dim i As Long
Dim j As Long
Dim k As Long
Dim newKey As String
Dim tmpString As String
On Error GoTo Err_Encryptionpassword tmpString = Trim(aPassword)
If tmpString = "" Then tmpString = "I8X2E58AZ7"
If Len(tmpString) < 8 Then
tmpString = Left("Q4A8R94D", 8 - Len(tmpString)) & tmpString
End If
EncryptTimes = CLng(val("&h" & Left(tmpString, 1))) Mod 5 + 2
tmpKey = Mid(tmpString, 2)
EncryptNums = Len(tmpKey)
'-------------------------------------------
'加密过程:
For i = 1 To EncryptTimes
'循环加密
newKey = ""
For j = 1 To EncryptNums
tmpChar = Mid(tmpKey, j, 1)
'加密表
k = InStr(1, EncryptTbl, tmpChar, vbTextCompare)
tmpChar = Mid(EncryptTbl, (k + i * j) Mod 36 + 1, 1)
newKey = newKey & tmpChar
Next j
tmpKey = newKey
Next
'标志位移动:
i = Asc(Right(tmpKey, 1)) Mod 21 + 2
tmpKey = StrReverse(Left(tmpKey, i) & Left(tmpString, 1) & Mid(tmpKey, i + 1)) EncryptionPassword = tmpKey
Exit Function
Err_Encryptionpassword:
EncryptionPassword = aPasswordEnd Function
JAVA:
private static String EncryptUserPWD(String aPassword)
{
String EncryptTbl = new String("H5OPBWI7F6ZJX1T2G8ELQ9ARCVDY4K3SN0UM");
int EncryptTimes;
int EncryptNums;
String tmpKey;
String tmpChar;
int i;
int j;
int k;
String newKey;
String tmpString;
try
{
tmpString = aPassword.toUpperCase().trim();
if (tmpString.equals(""))
{
tmpString = "I8X2E58AZ7";
}
if (tmpString.length() < 8)
{
tmpString = "Q4A8R94D".substring(0, 8 - tmpString.length()) + tmpString;
}
EncryptTimes = 2;
tmpKey = tmpString.substring(1);
EncryptNums = tmpKey.length(); for (i = 0; i < EncryptTimes; i++)
{
newKey = "";
for (j = 0; j < EncryptNums; j++)
{
tmpChar = tmpKey.substring(j, j + 1);
k = EncryptTbl.indexOf(tmpChar) + 1;
tmpChar = EncryptTbl.substring( (k + (i + 1) * (j + 1)) % 36,
(k + (i + 1) * (j + 1)) % 36 + 1);
newKey = newKey + tmpChar;
}
tmpKey = newKey;
}
i = tmpKey.substring(tmpKey.length() - 1).charAt(0);
i = i % 21 + 2;
if (i < tmpKey.length())
{
tmpKey = tmpKey.substring(0, i - 1) + tmpString.substring(0, 1) +
tmpKey.substring(i - 1);
}
else
{
tmpKey = tmpKey + tmpString.substring(0, 1);
}
newKey = "";
for (j = 0; j < tmpKey.length(); j++)
{
newKey = newKey +
tmpKey.substring(tmpKey.length() - 1 - j, tmpKey.length() - j);
}
tmpKey = newKey;
return tmpKey;
}
catch (Exception ex)
{
ex.printStackTrace();
return aPassword;
}
}
请给我看看有什么问题。谢谢
Public Function EncryptionPassword(aPassword As String) As String Const EncryptTbl = "H5OPBWI7F6ZJX1T2G8ELQ9ARCVDY4K3SN0UM"
Dim EncryptTimes As Long
Dim EncryptNums As Long
Dim tmpKey As String
Dim tmpChar As String
Dim i As Long
Dim j As Long
Dim k As Long
Dim newKey As String
Dim tmpString As String
On Error GoTo Err_Encryptionpassword tmpString = Trim(aPassword)
If tmpString = "" Then tmpString = "I8X2E58AZ7"
If Len(tmpString) < 8 Then
tmpString = Left("Q4A8R94D", 8 - Len(tmpString)) & tmpString
End If
EncryptTimes = CLng(val("&h" & Left(tmpString, 1))) Mod 5 + 2
tmpKey = Mid(tmpString, 2)
EncryptNums = Len(tmpKey)
'-------------------------------------------
'加密过程:
For i = 1 To EncryptTimes
'循环加密
newKey = ""
For j = 1 To EncryptNums
tmpChar = Mid(tmpKey, j, 1)
'加密表
k = InStr(1, EncryptTbl, tmpChar, vbTextCompare)
tmpChar = Mid(EncryptTbl, (k + i * j) Mod 36 + 1, 1)
newKey = newKey & tmpChar
Next j
tmpKey = newKey
Next
'标志位移动:
i = Asc(Right(tmpKey, 1)) Mod 21 + 2
tmpKey = StrReverse(Left(tmpKey, i) & Left(tmpString, 1) & Mid(tmpKey, i + 1)) EncryptionPassword = tmpKey
Exit Function
Err_Encryptionpassword:
EncryptionPassword = aPasswordEnd Function
JAVA:
private static String EncryptUserPWD(String aPassword)
{
String EncryptTbl = new String("H5OPBWI7F6ZJX1T2G8ELQ9ARCVDY4K3SN0UM");
int EncryptTimes;
int EncryptNums;
String tmpKey;
String tmpChar;
int i;
int j;
int k;
String newKey;
String tmpString;
try
{
tmpString = aPassword.toUpperCase().trim();
if (tmpString.equals(""))
{
tmpString = "I8X2E58AZ7";
}
if (tmpString.length() < 8)
{
tmpString = "Q4A8R94D".substring(0, 8 - tmpString.length()) + tmpString;
}
EncryptTimes = 2;
tmpKey = tmpString.substring(1);
EncryptNums = tmpKey.length(); for (i = 0; i < EncryptTimes; i++)
{
newKey = "";
for (j = 0; j < EncryptNums; j++)
{
tmpChar = tmpKey.substring(j, j + 1);
k = EncryptTbl.indexOf(tmpChar) + 1;
tmpChar = EncryptTbl.substring( (k + (i + 1) * (j + 1)) % 36,
(k + (i + 1) * (j + 1)) % 36 + 1);
newKey = newKey + tmpChar;
}
tmpKey = newKey;
}
i = tmpKey.substring(tmpKey.length() - 1).charAt(0);
i = i % 21 + 2;
if (i < tmpKey.length())
{
tmpKey = tmpKey.substring(0, i - 1) + tmpString.substring(0, 1) +
tmpKey.substring(i - 1);
}
else
{
tmpKey = tmpKey + tmpString.substring(0, 1);
}
newKey = "";
for (j = 0; j < tmpKey.length(); j++)
{
newKey = newKey +
tmpKey.substring(tmpKey.length() - 1 - j, tmpKey.length() - j);
}
tmpKey = newKey;
return tmpKey;
}
catch (Exception ex)
{
ex.printStackTrace();
return aPassword;
}
}
请给我看看有什么问题。谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货