nouveau challenges
This commit is contained in:
parent
3f600ad598
commit
9beb808890
1126
rootme/challenges/cryptanalyse/clair-connu-xor/ch3.bmp
Normal file
1126
rootme/challenges/cryptanalyse/clair-connu-xor/ch3.bmp
Normal file
File diff suppressed because one or more lines are too long
BIN
rootme/challenges/cryptanalyse/clair-connu-xor/ch3.out.bmp
Normal file
BIN
rootme/challenges/cryptanalyse/clair-connu-xor/ch3.out.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 484 KiB |
16
rootme/challenges/cryptanalyse/clair-connu-xor/decode.py
Normal file
16
rootme/challenges/cryptanalyse/clair-connu-xor/decode.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
key = "fallen"
|
||||||
|
keysz = len(key)
|
||||||
|
|
||||||
|
f = open("ch3.bmp", mode="rb")
|
||||||
|
data = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
out = bytearray()
|
||||||
|
for i in range(len(data)):
|
||||||
|
out.append(data[i] ^ ord(key[(i) % keysz]))
|
||||||
|
|
||||||
|
f = open("ch3.out.bmp", mode="wb")
|
||||||
|
f.write(out)
|
||||||
|
f.close()
|
Binary file not shown.
@ -0,0 +1,93 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#define KEY_SIZE 32
|
||||||
|
#define BUFF_SIZE 1024
|
||||||
|
|
||||||
|
unsigned int holdrand = 0;
|
||||||
|
|
||||||
|
static void Srand (unsigned int seed) {
|
||||||
|
holdrand = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Rand (void) {
|
||||||
|
return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* genere_key(void) {
|
||||||
|
int i;
|
||||||
|
static char key[KEY_SIZE+1];
|
||||||
|
const char charset[] =
|
||||||
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"123456789";
|
||||||
|
|
||||||
|
for(i = 0; i < KEY_SIZE; i++) {
|
||||||
|
key[i] = charset[Rand() % (sizeof(charset) - 1)];
|
||||||
|
}
|
||||||
|
key[KEY_SIZE] = '\0';
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypt_buffer(unsigned char *buffer, size_t size, char *key) {
|
||||||
|
size_t i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
for(i = 0; i < size; i++) {
|
||||||
|
if(j >= KEY_SIZE)
|
||||||
|
j = 0;
|
||||||
|
buffer[i] ^= key[j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypt_file(FILE *in, FILE *out) {
|
||||||
|
unsigned char buffer[BUFF_SIZE];
|
||||||
|
char *key;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
key = genere_key();
|
||||||
|
|
||||||
|
printf("[+] Using key : %s\n", key);
|
||||||
|
|
||||||
|
do {
|
||||||
|
size = fread(buffer, 1, BUFF_SIZE, in);
|
||||||
|
crypt_buffer(buffer, size, key);
|
||||||
|
fwrite(buffer, 1, size, out);
|
||||||
|
|
||||||
|
}while(size == BUFF_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
char path[128];
|
||||||
|
FILE *in, *out;
|
||||||
|
|
||||||
|
Srand(time(NULL));
|
||||||
|
|
||||||
|
if(argc != 2) {
|
||||||
|
printf("[-] Usage : %s <file>\n", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path)-1, "%s.crypt", argv[1]);
|
||||||
|
|
||||||
|
if((in = fopen(argv[1], "r")) == NULL) {
|
||||||
|
perror("[-] fopen (in) ");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((out = fopen(path, "w")) == NULL) {
|
||||||
|
perror("[-] fopen (out) ");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
crypt_file(in, out);
|
||||||
|
|
||||||
|
printf("[+] File %s crypted !\n", path);
|
||||||
|
printf("[+] DONE.\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user