c - Finding the key length -


simple xor decrypting:

in order break encryption, must make few assumptions:

1) key reasonably short (in our case, we're going assume it's less 30 bytes greater 3 bytes)

2) text plain ascii

3) text written plain english

4) text sufficiently longer key (or there multiple text passages encrypted same key)

description of key length:

if text english, know prevalent characters e,t,a,o,n,r,i,s,h,d,(...). more specifically, if randomly pick 2 characters text, know have greater 6% chance have same value. key length less 30 bytes.

to determine if given key length correct, use assumptions , subdivide encrypted text segments same size key length. then, xor each section section before , count number of equal values. math shows if ti == tj , then

bi^bj = (ti^kn)^(tj^kn)       = (ti^tj)^(kn^kn)       = (0)^(0)       = 0 

then should have key length. how it? thing have far read binary file , open binary file.

code:

int main(int argc, char* argv[]){     if (argc != 2) {         exit(exit_failure);     }     file* fp = fopen(argv[1], "rb");      printf("file opened: %s\n", argv[1]);                    fclose(fp);     return exit_success; } 

binary file:

http://i.stack.imgur.com/0dnto.png

for reason, can't post file or post link, otherwise guys might not have idea.

i assuming have data xored against key. key has fixed size , repeated on , on length of data.

let k key, of length k , let p array plain text , e array cipher text in it, then

p[0: k-1] xor k = e[0: k-1] p[k:2l-1] xor k = e[k:2k-1] 

so e[0: k-1] xor e[k:2k-1] same p[0: k-1] xor p[k:2k-1], is, it's xor of 2 plain text strings. can compute frequencies of these values how expect letters occur in plain text , make guesses @ substitutions based on frequencies.

construct guess @ plain text values p[0: k-1], xoring guess against e[0: k-1] give guess @ k. try key , iterate, improving guess. since english once have vowels should pretty easy guess.

to key length need try possible key-lengths, k, divide cipher text ranges of size k , xor pairs of them. @ number of character positions agree. heuristic probable key length corresponds widest agreement among pairs.

there handy tool this.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -