Challenge 'Didactic XOR Cipher 3' [Crypto]
Here is a string of bytes encoded in hex:
31cf55aa0c91fb6fcb33f34793fe00c72ebc4c88fd57dc6ba71e71b759d83588
This sequence has been encrypted with a cipher that works as follows. The first byte has been XOR'd with a byte we'll call 'b'. There is a another component to the key, a byte we'll call 'x'. Each time a byte gets XOR'd by b, the following change is executed:
b = (b + x) % 256
In other words, the cipher byte changes with each character encrypted.
Bien me he puesto a programar una rutina que vaya probando las soluciones y que solo me imprima caracteres ascii pertenecientes a texto, pero en la salida no he podido ver texto coherente hast ahora.
Si b y x pueden tener 256 valores cada uno, entonces la posibilidad de combinaciones es de 65536 combinaciones posibles. Voy tomando cada representacion de 8 Bytes de la cadena de texto y probando haciendoles XOR a ver si caen dentro del campo de letras del código ascii y mandandolos a imprimir
He aqui la rutina que he programado:
Código
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char* argv[]) { const char* string = "31cf55aa0c91fb6fcb33f34793fe00c72ebc4c88fd57dc6ba71e71b759d83588"; for(int b=0; b<256; b++) { for(int x=0; x<256; x++) { int bTest = b; //saving the value of b for not chaging inside the other for cicle :) for(int i=0; i<strlen(string); i+=2) { //Tranform to hex number char *end; if ( ( (bTest^number)<64 && ( (bTest^number)!=32) ) || (bTest^number)>122 ) break; bTest = (bTest + x) % 256; } //End of myByte } //End of x } //End of b return 0; }
Solo obtengo pura basura a la salida caractres ascii osea texto pero sin ningun sentido.