#include<stdio.h>
#include<stdlib.h>
int getNumberCount(int number){
int index =0;
while(number >0){
number = number >> 1;
index++;
}
return 1 << (index - 1);
}
unsigned char numberLeftMove( unsigned char number, int numberCount, int loopMoveCount)
{
unsigned char retNumber = number;
for(int i = 0; i < loopMoveCount; i++){
if((retNumber & numberCount) > 0){
retNumber = ((retNumber^numberCount) << 1) + 1;
}else{
retNumber = retNumber << 1;
}
}
return retNumber;
}
unsigned char numberRightMove( unsigned char number, int numberCount, int loopMoveCount)
{
unsigned char retNumber = number;
for(int i = 0; i < loopMoveCount; i++){
if((retNumber & 1) > 0){
retNumber = (retNumber >> 1) | numberCount;
}else{
retNumber = retNumber >> 1 ;
}
}
return retNumber;
}
int main() {
unsigned char password[71] = {71,114,101,97,116,32,105,100,101,97,108,32,98,117,116,32,116,104,114,111,117,103,104,32,115,101,108,102,108,101,115,115,32,115,116,114,117,103,103,108,101,32,97,110,100,32,115,97,99,114,105,102,105,99,101,32,116,111,32,97,99,104,105,101,118,101,46};
unsigned char SecretLetters[71] = {0}; //密函
unsigned char annex[71] = {0}; //附件
int loopMoveCount = 0; //循环位移数
int secreCount = 0; //密函长度
int annexCount = 0; //附件长度
char endChar;
int i;
int numberCount = 0;
while(1){
scanf("%hhu%c", &SecretLetters[secreCount++], &endChar);
if(endChar == '\n'){
break;
}
}
while(1){
scanf("%hhu%c", &annex[annexCount++], &endChar);
if(endChar == '\n'){
break;
}
}
scanf("%d", &loopMoveCount);
for (i = 0; i < secreCount; i++) {
SecretLetters[i] ^= password[i];
}
for (i = 0; i < annexCount; i++) {
numberCount = getNumberCount(annex[i]);
if(loopMoveCount>0){
annex[i] = numberLeftMove(annex[i], numberCount, loopMoveCount);
}
else {
annex[i] = numberRightMove(annex[i], numberCount,-loopMoveCount);
}
}
for (i = 0; i < secreCount; i++) {
SecretLetters[i] = SecretLetters[i] & annex[i];
if(i > 0){
printf(" ");
}
printf("%hhu", SecretLetters[i]);
}
return 0;
}
/*
9 23 19 132 6 192 6 27 10 15 13 94 29 14 3 69 4 17 29 18 73 18 24 78
201 172 222 239 206 5 254 237 221 207 172 20 252 61 206 188 21 175 253 254 68 190 126 215
3
*/
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/990332759496134.png?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
看看我的亲测有效,希望有什么问题可以私聊我