求大侠帮我给这个c++程序改成java程序 (100分重谢)
是个以前项目综合业务系统行员密码算法现在要改成java的
/* Function : iCryptPasswdP
Usage Range : 对外提供
Purpose : 对行员口令字段加密
Parameter In: Passwd 未加密口令6位
Teller行员代码6位
Parameter Out: Return Code 非NULL串:加密后口令
NULL:原始口令字段为空
*/
char *iCryptPasswdP(char *Teller,char *Passwd)
{
/* 口令中不允许以空格结束*/
static char Tmp_Passwd[PTELRPASSWD_LEN+1];
charTeller_Buff[PTELR_LEN+1];
charPasswd_Buff[PPASSWD_LEN+2];
inti,j,k,m,n;
chara,b;
memset(Teller_Buff,0,sizeof(Teller_Buff));
memset(Passwd_Buff,0,sizeof(Passwd_Buff));
strcat(Teller_Buff,(char *)delsp(Teller,PTELR_LEN)); 去掉空格再赋给teller_buff
strcat(Passwd_Buff,(char *)delsp(Passwd,PPASSWD_LEN));
memset(Tmp_Passwd,0,sizeof(Tmp_Passwd));
n = strlen(Passwd_Buff);
if(n == 0)
return NULL;
if(strlen(Teller_Buff) != PTELR_LEN)
return NULL;
k = 0;
Passwd_Buff[PPASSWD_LEN] = 'A '+n;
Passwd_Buff[PPASSWD_LEN+1] = 0;
m = 0;
for(i=0;i <=PPASSWD_LEN+1;i++) {
if(i < PPASSWD_LEN)
j = Passwd_Buff[i]+Teller_Buff[PTELR_LEN-i-1]- '0 ' ;
else
j = Passwd_Buff[(i+n)%PTELR_LEN]+Teller_Buff[PTELR_LEN-((i+n) % PTELR_LEN)-1]- '0 ' ;
j = j+ (m+i+j/5) % PTELR_LEN;
m = 0;
j = j*j;
if(j > = 10000){
j %= 10000;
m += 1;
}
a = j /100;
b = j % 100;
m = m*2;
if(a < '0 '){
a = a+ '0 ';
m = m+1;
}
m = m*2;
if(a> '9 ' && a < 'A ') {
a = a+ 10;
m = m+1;
} else if(a> 'Z ' && a < 'a ') {
a = a+ 10;
m = m+1;
}
Tmp_Passwd[k] = a ;
m = m*2;
if(b < '0 ') {
b = b+ '0 ';
m = m+1;
}
m = m*2;
if(b> '9 ' && b < 'A ') {
b = b+ 10;
m = m+1;
}else if(b> 'Z ' && b < 'a '){
b = b+ 10;
m = m+1;
}
Tmp_Passwd[k+1] = b ;
k += 2;
if(i <PPASSWD_LEN)
Passwd_Buff[PPASSWD_LEN+1] += m*(i+1);
if(i == PPASSWD_LEN)
Passwd_Buff[PPASSWD_LEN+1] %= 100;
}
return Tmp_Passwd;
}
[解决办法]
哈~ 我忽然发现我的前途一片光明 遇上不会的可以 百度 GOOGLE 再不行还可以像楼主这样把代码帖上来让CSDN里的大虾们搞定......哎 看样子谁都可以当程序员了 估计再过不久我就要下岗了 可我才刚开始做J2EE啊 5555555 悲哀啊~
------解决方案--------------------
char[] iCryptPasswdP(char[] Teller,char[] Passwd)
{
/* 口令中不允许以空格结束*/
char[] Tmp_Passwd = new char[PTELRPASSWD_LEN+1];
char[] Teller_Buff = new char[PTELR_LEN+1];
char[] Passwd_Buff = new char[PPASSWD_LEN+2];
inti,j,k,m,n;
chara,b;
Teller_Buff = new String(Teller).replace( " ", " ").toCharArray();
Passwd_Buff = new String(Passwd).replace( " ", " ").toCharArray();
n = Passwd_Buff.length;
if(n == 0)
return null;
if(Teller_Buff.length != PTELR_LEN)
return null;
k = 0;
Passwd_Buff[PPASSWD_LEN] = (char)( 'A ' + n);
Passwd_Buff[PPASSWD_LEN+1] = 0;
m = 0;
for(i=0;i <=PPASSWD_LEN+1;i++) {
if(i < PPASSWD_LEN)
j = Passwd_Buff[i]+Teller_Buff[PTELR_LEN-i-1]- '0 ' ;
else
j = Passwd_Buff[(i+n)%PTELR_LEN]+Teller_Buff[PTELR_LEN-((i+n) % PTELR_LEN)-1]- '0 ' ;
j = j+ (m+i+j/5) % PTELR_LEN;
m = 0;
j = j*j;
if(j > = 10000){
j %= 10000;
m += 1;
}
a = (char)(j /100);
b = (char)(j % 100);
m = m*2;
if(a < '0 '){
a = (char)(a + '0 ');
m = m+1;
}
m = m*2;
if(a> '9 ' && a < 'A ') {
a = (char)(a+ 10);
m = m+1;
} else if(a> 'Z ' && a < 'a ') {
a = (char)(a+ 10);
m = m+1;
}
Tmp_Passwd[k] = a ;
m = m*2;
if(b < '0 ') {
b = (char)(b+ '0 ');
m = m+1;
}
m = m*2;
if(b> '9 ' && b < 'A ') {
b = (char)(b+ 10);
m = m+1;
}else if(b> 'Z ' && b < 'a '){
b = (char)(b+ 10);
m = m+1;
}
Tmp_Passwd[k+1] = b ;
k += 2;
if(i <PPASSWD_LEN)
Passwd_Buff[PPASSWD_LEN+1] += m*(i+1);
if(i == PPASSWD_LEN)
Passwd_Buff[PPASSWD_LEN+1] %= 100;
}
return Tmp_Passwd;
}