我的第一次发帖。最近开始编码了很多。我想到我完成了另一个谷歌foobar挑战,但是当我用谷歌验证这个代码时我得到错误3/5次(没有关于图表的反馈出现错误。)我生成10时没有错误百万随机图...
无论如何,这是我的代码来反转哈希(129 * message [i] XOR message [0])%256:
public static int[] answer(int[] digest){
int[] message = new int[digest.length];
message[0] = 0;
for(int i = 1; i < digest.length; i++){
for(int n = 0; n < 256; n++){//find the possible inverses of mod 256...should figure out what to max n out at, 256*256?
//the digest number and message number should be 1 apart.
int modInverse = n*256+digest[i];//x mod y = z if x = ny + z...find possible values of inverse mod 256
int xorInverse = modInverse^message[i-1];//undo XOR using all of the tested modInverse and previous message...might need to do previous digest?
int divided = xorInverse/129;//undo multiplying by 129.
int remainder = xorInverse%129;//see if there is no remainder.
if(remainder == 0){
message[i] = divided;
break;
}
}
}
return message;
}
以下是有人实际发布挑战的链接:https://goo.gl/Tw4LpA