当前位置: 技术问答>java相关
谁能帮我把这段Java转换成C++,或者告诉我方法
来源: 互联网 发布时间:2015-05-03
本文导语: 是一段MD5的算法 有些类型和操作符我不太明白因为没学过JAVA. 如tb>>>4是什么意思 下面是使用JAVA语言对表现方法的描述: public static String bintoascii(byte []bySourceByte) { int len,i; byte tb; char high,tmp,low; String...
是一段MD5的算法
有些类型和操作符我不太明白因为没学过JAVA. 如tb>>>4是什么意思
下面是使用JAVA语言对表现方法的描述:
public static String bintoascii(byte []bySourceByte)
{
int len,i;
byte tb;
char high,tmp,low;
String result=new String();
len=bySourceByte.length;
for(i=0;i>>4)&0x000f);
if(tmp>=10)
high=(char)('a'+tmp-10);
else
high=(char)('0'+tmp);
result+=high;
tmp=(char)(tb&0x000f);
if(tmp>=10)
low=(char)('a'+tmp-10);
else
low=(char)('0'+tmp);
result+=low;
}
return result;
}
下面是一些字符串进行MAC并按上述方法进行转换后获得的结果:
Ø MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
Ø MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
Ø MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
Ø MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
Ø MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
Ø MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f
Ø MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = 57edf4a22be3c955ac49da2e2107b67a
有些类型和操作符我不太明白因为没学过JAVA. 如tb>>>4是什么意思
下面是使用JAVA语言对表现方法的描述:
public static String bintoascii(byte []bySourceByte)
{
int len,i;
byte tb;
char high,tmp,low;
String result=new String();
len=bySourceByte.length;
for(i=0;i>>4)&0x000f);
if(tmp>=10)
high=(char)('a'+tmp-10);
else
high=(char)('0'+tmp);
result+=high;
tmp=(char)(tb&0x000f);
if(tmp>=10)
low=(char)('a'+tmp-10);
else
low=(char)('0'+tmp);
result+=low;
}
return result;
}
下面是一些字符串进行MAC并按上述方法进行转换后获得的结果:
Ø MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
Ø MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
Ø MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
Ø MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
Ø MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
Ø MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f
Ø MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = 57edf4a22be3c955ac49da2e2107b67a
|
String bintoascii(byte bySourceByte[])
{
int len1,i;
byte tb;
char high,tmp,low;
String result;
len1=len(bySourceByte);
for(i=0;i>>4)&0x000f);
if(tmp>=10)
high=(char)('a'+tmp-10);
else
high=(char)('0'+tmp);
result+=high;
tmp=(char)(tb&0x000f);
if(tmp>=10)
low=(char)('a'+tmp-10);
else
low=(char)('0'+tmp);
result+=low;
}
return result;
}
{
int len1,i;
byte tb;
char high,tmp,low;
String result;
len1=len(bySourceByte);
for(i=0;i>>4)&0x000f);
if(tmp>=10)
high=(char)('a'+tmp-10);
else
high=(char)('0'+tmp);
result+=high;
tmp=(char)(tb&0x000f);
if(tmp>=10)
low=(char)('a'+tmp-10);
else
low=(char)('0'+tmp);
result+=low;
}
return result;
}
|
#include
#include
#include
using namespace std;
string bintoascii(char bySourceByte[])
{
int len,i;
char tb;
char high,tmp,low;
len=strlen(bySourceByte);
string result;
for(i=0;i>4)&0x000f);
if(tmp>=10) {
high=(char)('a'+tmp-10);
} else {
high=(char)('0'+tmp);
}
result+=high;
tmp=(char)(tb&0x000f);
if(tmp>=10) {
low = (char)('a'+tmp-10);
} else {
low = (char)('0'+tmp);
}
result+=low;
}
return result;
}
int
main(int args, char *argv[])
{
if (args
#include
#include
using namespace std;
string bintoascii(char bySourceByte[])
{
int len,i;
char tb;
char high,tmp,low;
len=strlen(bySourceByte);
string result;
for(i=0;i>4)&0x000f);
if(tmp>=10) {
high=(char)('a'+tmp-10);
} else {
high=(char)('0'+tmp);
}
result+=high;
tmp=(char)(tb&0x000f);
if(tmp>=10) {
low = (char)('a'+tmp-10);
} else {
low = (char)('0'+tmp);
}
result+=low;
}
return result;
}
int
main(int args, char *argv[])
{
if (args