Code in 1.c#
///<summary>
///< functions: Encode>
///function: Converts a string content into a 16-encoded data encoding, and its inverse procedure is decode
///parameter description: br>///Strencode The original string that needs to be transformed
///the process of converting a character directly into a Unicode character, such as the number "3"-->0033, the Chinese character "I"-->u+6211
the///function Dec The process of ODE is the inverse process of encode.
///</summary>
///<param name= "Strencode" ></PARAM>
///<returns></ret Urns>
public static string Encode (String strencode)
{
String strreturn = ";/store converted encoding
foreach (Short shortx in Strencode.tochararray ())
{
Strreturn = = Shortx. ToString ("X4");
}
Return Strreturn
///<summary>
///< functions: Decode>
///effect: Converting 16-encoded data encoding to a string is the reverse process of encode
///</sum Mary>
///<param name= "Strdecode" ></PARAM>
///<returns></returns>
Publ IC static string Decode (String strdecode)
{
String sresult = "";
for (int i = 0; i < STRDECODE.LENGTH/4 i++)
{
Sresult + = (char) short. Parse (Strdecode.substring (i * 4, 4), global::system.globalization.numberstyles.hexnumber);
}
Return Sresult
}
Code in the 2.VB6
'*******************************************************************
'<函数:Encode>
'作用:将字符串内容转化为16进制数据编码,其逆过程是Decode
'参数说明:
'strSource 需要转化的原始字符串
Public Function Encode(strEncode As String) As String
Dim i As Long
Dim chrTmp$
Dim ByteLower$, ByteUpper$
Dim strReturn$ '存储转换后的编码
For i = 1 To Len(strEncode)
chrTmp$ = Mid(strEncode, i, 1)
ByteLower$ = Hex$(AscB(MidB$(chrTmp$, 1, 1)))
If Len(ByteLower$) = 1 Then ByteLower$ = "0" & ByteLower$
ByteUpper$ = Hex$(AscB(MidB$(chrTmp$, 2, 1)))
If Len(ByteUpper$) = 1 Then ByteUpper$ = "0" & ByteUpper$
strReturn$ = strReturn$ & ByteUpper$ & ByteLower$
Next
Encode = strReturn$
End Function
'</函数:Encode>