是个以前项目综合业务系统行员密码算法现在要改成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];
char Teller_Buff[PTELR_LEN+1];
char Passwd_Buff[PPASSWD_LEN+2];
int i,j,k,m,n;
char a,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;
}
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];
char Teller_Buff[PTELR_LEN+1];
char Passwd_Buff[PPASSWD_LEN+2];
int i,j,k,m,n;
char a,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;
}
{
/* 口令中不允许以空格结束 */
char[] Tmp_Passwd = new char[PTELRPASSWD_LEN+1];
char[] Teller_Buff = new char[PTELR_LEN+1];
char[] Passwd_Buff = new char[PPASSWD_LEN+2];
int i,j,k,m,n;
char a,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;
}
Passwd_Buff = new String(Passwd).replace(" ", "").toCharArray();
换成
String temp = new String(Teller);
Teller_Buff = (temp.endsWith(" ") ? temp.substring(0, temp.length() - 1) : temp).toCharArray();
temp = new String(Passwd);
Passwd_Buff = (temp.endsWith(" ") ? temp.substring(0, temp.length() - 1) : temp).toCharArray();
public class Test {
public static void main(String [] args)throws Exception
{
char[] teller = new char[]{'c','h','e','n','g','q'};
char[] passwd = new char[]{'1','1','1','1','1','1'};
char[] result = iCryptPasswdP(teller,passwd);
System.out.println(result);
} public static char[] iCryptPasswdP(char[] Teller, char[] Passwd)
{
/* 口令中不允许以空格结束 */
char[] Tmp_Passwd = new char[16 + 1];
char[] Teller_Buff = new char[6 + 1];
char[] Passwd_Buff = new char[6 + 2];
int i, j, k, m, n;
char a, b;
String temp = new String(Teller);
Teller_Buff = (temp.endsWith(" ") ? temp.substring(0, temp.length() - 1) : temp).toCharArray();
temp = new String(Passwd);
Passwd_Buff = (temp.endsWith(" ") ? temp.substring(0, temp.length() - 1) : temp).toCharArray(); n = Passwd_Buff.length;
if (n == 0)
return null;
if (Teller_Buff.length != 6)
return null; k = 0;
char[] temp1 = new char[8];
for(i=0;i<temp1.length;i++){
if(i<Passwd_Buff.length){
temp1[i] = Passwd_Buff[i];
}
else
temp1[i] = 0;
}
Passwd_Buff = new char [8];
Passwd_Buff = temp1;
Passwd_Buff[6] = (char) ('A' + n);
Passwd_Buff[6 + 1] = 0;
m = 0;
for (i = 0; i <= 6 + 1; i++) {
if (i < 6)
j = Passwd_Buff[i] + Teller_Buff[6 - i - 1] - '0';
else
j = Passwd_Buff[(i + n) % 6]
+ Teller_Buff[6 - ((i + n) % 6) - 1] - '0';
j = j + (m + i + j / 5) % 6;
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 < 6)
Passwd_Buff[6 + 1] += m * (i + 1);
if (i == 6)
Passwd_Buff[6 + 1] %= 100;
}
return Tmp_Passwd;
}}