如何把这VB代码转为C#?
Public Function Encode(ByVal S As String) As String
On Error GoTo acd
If Len(S) = 0 Then Exit Function
Dim Buff() As Byte
Buff = StrConv(S, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
Dim outs As String
i = UBound(Buff) + 1
outs = Space(2 * i)
Dim Temps As String
For i = 0 To UBound(Buff)
Randomize Time
j = CByte(5 * (Math.Rnd()) + 0) '最大产生的随机数只能是5,不能再大了,再大的话,就要多用一个字节
Buff(i) = Buff(i) Xor j
k = Buff(i) Mod Len(mstr)
m = Buff(i) \ Len(mstr)
m = m * 2 ^ 3 + j
Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
Mid(outs, 2 * i + 1, 2) = Temps
Next
Encode = outs
Exit Function
acd:
End FunctionPublic Function Decode(ByVal S As String) As String
On Error GoTo acd
Dim i As Long
Dim j As Byte
Dim k As Byte
Dim m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
Dim t1 As String, t2 As String
Dim Buff() As Byte
Dim n As Long
n = 0
For i = 1 To Len(S) Step 2
t1 = Mid(S, i, 1)
t2 = Mid(S, i + 1, 1)
k = InStr(1, mstr, t1) - 1
m = InStr(1, mstr, t2) - 1
j = m \ 2 ^ 3
m = m - j * 2 ^ 3
ReDim Preserve Buff(n)
Buff(n) = j * Len(mstr) + k
Buff(n) = Buff(n) Xor m
n = n + 1
Next
Decode = StrConv(Buff, vbUnicode)
Exit Function
acd:
Decode = ""
End Function谢了
Public Function Encode(ByVal S As String) As String
On Error GoTo acd
If Len(S) = 0 Then Exit Function
Dim Buff() As Byte
Buff = StrConv(S, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
Dim outs As String
i = UBound(Buff) + 1
outs = Space(2 * i)
Dim Temps As String
For i = 0 To UBound(Buff)
Randomize Time
j = CByte(5 * (Math.Rnd()) + 0) '最大产生的随机数只能是5,不能再大了,再大的话,就要多用一个字节
Buff(i) = Buff(i) Xor j
k = Buff(i) Mod Len(mstr)
m = Buff(i) \ Len(mstr)
m = m * 2 ^ 3 + j
Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
Mid(outs, 2 * i + 1, 2) = Temps
Next
Encode = outs
Exit Function
acd:
End FunctionPublic Function Decode(ByVal S As String) As String
On Error GoTo acd
Dim i As Long
Dim j As Byte
Dim k As Byte
Dim m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
Dim t1 As String, t2 As String
Dim Buff() As Byte
Dim n As Long
n = 0
For i = 1 To Len(S) Step 2
t1 = Mid(S, i, 1)
t2 = Mid(S, i + 1, 1)
k = InStr(1, mstr, t1) - 1
m = InStr(1, mstr, t2) - 1
j = m \ 2 ^ 3
m = m - j * 2 ^ 3
ReDim Preserve Buff(n)
Buff(n) = j * Len(mstr) + k
Buff(n) = Buff(n) Xor m
n = n + 1
Next
Decode = StrConv(Buff, vbUnicode)
Exit Function
acd:
Decode = ""
End Function谢了
解决方案 »
- c# 正则表达式求教
- 请推荐.Net下比较好的更新日志工具?
- lsvBlockcolorSet.SelectedItems[0])中的0表示什么?
- 用c#如何获取文件快捷方式的图标?
- 局部打印
- CSDN社区有可用分是怎么给的?
- 这种功能怎么实现呢?
- 我在form里用双缓冲,调用Invalidate屏幕无闪烁,我从panel派生了个控件,也用了双缓冲,但我调用控件的Invalidate时,控件闪烁,该怎么处理?
- 操作picturebox的一个问题
- 古怪的ConfigurationManager,添加引用System.Configuration.dll依然无效
- 一个简单的查询问题?
- 数据库连接问题
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
高手们
刚才问了一下,有人说我给我分数少(论坛默认的20分)
现在再开一贴,特意加到100分(不够再说吧)
还是有人说分数少那我把我所有的分数全给了,行不行?
public string Encode(string S) {
// TODO: On Error GoTo Warning!!!: The statement is not translatable
if ((S.Length == 0)) {
// TODO: Exit Function: Warning!!! Need to return the value
}
return;
byte[] Buff;
Buff = StrConv(S, vbFromUnicode);
long i;
byte j;
byte k;
byte m;
string mstr;
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
string outs;
i = (UBound(Buff) + 1);
outs = Space((2 * i));
string Temps;
for (i = 0; (i <= UBound(Buff)); i++) {
Randomize;
Time;
j = byte.Parse(((5 * Math.Rnd())
+ 0));
Buff[i] = Buff[i];
j;
k = (Buff[i] % mstr.Length);
m = Buff[i];
mstr.Length;
m = ((m * 2) | (3 + j));
// TODO: Warning!!! The operator should be an XOR ^ instead of an OR, but not available in CodeDOM
Temps = (mstr.Substring(k, 1) + mstr.Substring(m, 1));
outs.Substring((2 * i), 2) = Temps;
}
return outs;
acd:
}
public string Decode(string S) {
// TODO: On Error GoTo Warning!!!: The statement is not translatable
long i;
byte j;
byte k;
byte m;
string mstr;
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
string t1;
string t2;
byte[] Buff;
long n;
n = 0;
for (i = 1; (i <= S.Length); i = (i + 2)) {
t1 = S.Substring((i - 1), 1);
t2 = S.Substring(i, 1);
k = ((mstr.IndexOf(t1, 0) + 1)
- 1);
m = ((mstr.IndexOf(t2, 0) + 1)
- 1);
j = m;
(2 | 3);
// TODO: Warning!!! The operator should be an XOR ^ instead of an OR, but not available in CodeDOM
m = ((m
- (j * 2))
| 3);
// TODO: Warning!!! The operator should be an XOR ^ instead of an OR, but not available in CodeDOM
object Preserve;
Buff[n];
Buff[n] = ((j * mstr.Length)
+ k);
Buff[n] = Buff[n];
m;
n = (n + 1);
}
return StrConv(Buff, vbUnicode);
acd:
return "";
}
http://www.kamalpatel.net/convertcsharp2vb.aspx
http://www.carlosag.net/tools/codetranslator/default.aspx