论坛元老
 
- 积分
- 3571
- 金钱
- 3571
- 注册时间
- 2014-12-2
- 在线时间
- 365 小时
|
发表于 2016-3-4 12:50:17
|
显示全部楼层
随手写一个:
[mw_shl_code=c,true]
# include "stdio.h"
void Encrypt(char *s1, char *s2)
{
const char SS[] = "~!@#$%^&*_+}:?>.";
while (*s1)
{
*s2++ = SS[(*s1)>>4];
*s2++ = SS[(*s1)&0xF];
s1++;
}
*s2 = '\0';
}
void Decrypt(char *s1, char *s2)
{
int i;
const char SS[] = "~!@#$%^&*_+}:?>.";
while (*s1)
{
for (i = 0; i < 16; i++)
{
if (SS == (*s1))
{
*s2 = i << 4;
break;
}
}
s1++;
for (i = 0; i < 16; i++)
{
if (SS == (*s1))
{
*s2 |= i;
break;
}
}
s1++;
s2++;
}
*s2 = '\0';
}
int main(void)
{
char s[80];
char re[80];
printf("Input string:");
scanf("%s", s);
Encrypt(s, re);
printf("Encrypt is : [%s]\n", re);
Decrypt(s, re);
printf("Decrypt is : [%s]\n", re);
return 0;
}[/mw_shl_code]
|
|