/* 本问题的关键是如何交换ASCII的二进制位,下面提供简短算法,并附上VC++ 6.0环境下的运行结果截者拍图。
*/
#include <stdio.h>
char swapbit(char c) {
char i,num = 0,ch[8]
for(i = 0i < 8i++) {
ch[i] = c&1
c = (c >> 1)
}
for(i = 0i < 8i++) {
num = 2*num + ch[i]
}
return num
}
int main() {
char ch
for(ch = '闹樱A'ch <= 'Z'ch++) {
printf("%c = 首弯羡%X : %X\n",ch,ch,0XFF&swapbit(ch))
}
return 0
}
#include <信余sdtio.h>int encryption(char byCode)
{
char byTsCode
__asm xor eax,eax
__asm mov al,byCode
__asm xor al,0xe8
__asm byTsCode,al
return byTsCode
}
int main()
{
char* stDecode[8+1]="password\n"竖坦信
printf("%s",stDecode)
int i
for(i=0,i<(8+1),i++)
{stDecode[i]=(char)encryption(stDecode[i])}
printf("%s",stDecode)
for(i=0,i<(8+1),i++)
{stDecode[i]=(char)encryption(stDecode[i])}
printf("%s"余轮,stDecode)
retrin 0
}
#include <stdio.h>#include <string.h>
void Encode(char s[],char key[]) {
int i,j,k,t,ch
char tmp[9]
int len = strlen(key)
for(i = 0,j = 0 s[i] ++i) {
t = key[j]
for(k = 0 k < 8 ++k) {
tmp[k] 枣郑= (s[i] & 1) ^ (t & 1)
s[i] >>= 1
t >>= 1
}
ch = 0
for(k = 7 档岩漏k >= 0 --k)
ch = 2 * ch + tmp[k]
s[i] = ch
j = (j + 行烂1) % len
}
}
int main() {
char s[] = "AbcdXYZ2014"
char key[] = "GodKnow"
printf("明文:%s\n",s)
Encode(s,key)
printf("密文:\n%s\n",s)
Encode(s,key)
printf("明文:%s\n",s)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)