Skip to content

This program generates a random key with a specified number of bits and then uses brute-force search to find the key by iterating through every possible value until it finds a match. The time taken to find the key is also recorded.

License

Notifications You must be signed in to change notification settings

DanielProg39/Key-Space-Brute-Force

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Key Space Brute Force

This program generates a random key with a specified number of bits and then uses brute-force search to find the key by iterating through every possible value until it finds a match. The time taken to find the key is also recorded.


The implementation

The provided program implements a brute-force algorithm to find a key with a specified number of bits in size. The key_space function calculates the total number of keys that can be generated with a given number of bits, represented as a BigUint type. The brute_force function takes a specified number of bits as input and generates a random key within the key space using the rand::thread_rng function. It then iterates through all possible keys (from 0 to the key space) and checks if the current key is equal to the randomly generated key. If the key is found, the function prints the number of bits of the key and the time it took to find the key. In the main function, the program first calculates and prints the key space for various numbers of bits, ranging from 8 to 4096 bits. It then calls the brute_force function for each of these numbers of bits.

The Output

Key space for 8-bit key: 256
Key space for 16-bit key: 65536
Key space for 32-bit key: 4294967296
Key space for 64-bit key: 18446744073709551616
Key space for 128-bit key: 340282366920938463463374607431768211456
Key space for 256-bit key: 115792089237316195423570985008687907853269984665640564039457584007913129639936
Key space for 512-bit key: 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096
Key space for 1024-bit key: 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216
Key space for 2048-bit key: 32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656
Key space for 4096-bit key: 1044388881413152506691752710716624382579964249047383780384233483283953907971557456848826811934997558340890106714439262837987573438185793607263236087851365277945956976543709998340361590134383718314428070011855946226376318839397712745672334684344586617496807908705803704071284048740118609114467977783598029006686938976881787785946905630190260940599579453432823469303026696443059025015972399867714215541693835559885291486318237914434496734087811872639496475100189041349008417061675093668333850551032972088269550769983616369411933015213796825837188091833656751221318492846368125550225998300412344784862595674492194617023806505913245610825731835380087608622102834270197698202313169017678006675195485079921636419370285375124784014907159135459982790513399611551794271106831134090584272884279791554849782954323534517065223269061394905987693002122963395687782878948440616007412945674919823050571642377154816321380631045902916136926708342856440730447899971901781465763473223850267253059899795996090799469201774624817718449867455659250178329070473119433165550807568221846571746373296884912819520317457002440926616910874148385078411929804522981857338977648103126085903001302413467189726673216491511131602920781738033436090243804708340403154190336
Found 8-bit key in 0ms
Found 16-bit key in 0ms

It's normal for the program to take a long time to find a 32-bit key and further, as the search space is much larger than for a 16-bit key. The time it takes to find a key will increase exponentially as the key size increases. The program works by brute force, trying every possible key in the key space until it finds the correct one, so the larger the key space, the more time it takes to find the key.

About

This program generates a random key with a specified number of bits and then uses brute-force search to find the key by iterating through every possible value until it finds a match. The time taken to find the key is also recorded.

Topics

Resources

License

Stars

Watchers

Forks

Languages