需要蛮力code为地穴帮助(3) [英] Need help with brute force code for crypt(3)

查看:180
本文介绍了需要蛮力code为地穴帮助(3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用于UNIX将破解地穴(3)加密C到开发程序。
最天真的方式做到这一点是暴力破解,我猜。我想我应该创建一个包含通过密码可以,然后让他们的所有可能的排列,并将其存储在一个二维数组(其中所有的1个字符的密码得到的已保存的第一行等中)的所有符号的数组循环。有没有更好的方式来做到这一点?这是pretty凌乱的循环。

I am trying to develop a program in C that will "crack" the crypt(3) encryption used by UNIX. The most naive way to do it is brute forcing I guess. I thought I should create an array containing all the symbols a password can have and then get all possible permutations of them and store them in a two-dimensional array (where all the 1 character passwords get's saved in the first row etc.) through for loops. Is there any better way to do this? It's pretty messy with the loops.

推荐答案

假设只有62个字符可以使用,存储所有可能的8个字符的密码需要62 ^ 8 = 198太字节。

Assuming only 62 different characters can be used, storing all the possible 8 character passwords requires 62^8=198 Terabytes.

要anwser您的循环的问题,这里是一些code遍历一个给定的len的所有可能的密码,使用字符一组给定:

To anwser you loop question, here is some code to loop over all the possible passwords of a given len, using the characters for a given set:

int len = 3;
char letters[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int nbletters = sizeof(letters)-1;

int main() {
    int i, entry[len];
    for(i=0 ; i<len ; i++) entry[i] = 0;
    do {
        for(i=0 ; i<len ; i++) putchar(letters[entry[i]]);
        putchar('\n');
        for(i=0 ; i<len && ++entry[i] == nbletters; i++) entry[i] = 0;
    } while(i<len);
}

主要的部分是最后的的循环。在大多数情况下,它仅递增第一个条目,并停止在那里,因为这条目尚未达到nbletters。如果条目到达nbletter,这意味着它有返回到零,并且它的下一个条目的转递增。这的确是一个不寻常的循环条件:循环继续,直到没有溢出。该循环仅发生在最坏的情况下:当几个条目的最后一个元素上

The main part is the last for loop. In most cases, it only increments the first entry, and stops there, as this entry has not reached nbletters. If the entry reaches nbletter, it means it has to return to zero, and it's the turn of the next entry to be incremented. It is indeed an unusual loop condition: the loop continues until there is no overflow. The looping only occurs in the worst case: when several entries are on the last element.

想像一下当前词是zzzc的情况。反过来,每个条目递增,检测其溢出,它被复位为0,并且下一个条目被认为是,直到最后一个条目而不会溢出,得到000D

Imagine the case where the current word is "zzzc". In turn, each entry is incremented, its overflow is detected, it is reset to 0, and the next entry is considered, until the last entry which does not overflow, to give "000d".

这篇关于需要蛮力code为地穴帮助(3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆