Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/ptrace.h>
- #include <time.h>
- #include <errno.h>
- #include <limits.h>
- #include <getopt.h>
- void welcome() {
- printf("\n");
- printf("\n");
- printf(" .... NO! ... ... MNO! ...\n");
- printf(" ..... MNO!! ...................... MNNOO! ...\n");
- printf(" ..... MMNO! ......................... MNNOO!! .\n");
- printf("..... MNOONNOO! MMMMMMMMMMPPPOII! MNNO!!!! .\n");
- printf(" ... !O! NNO! MMMMMMMMMMMMMPPPOOOII!! NO! ....\n");
- printf(" ...... ! MMMMMMMMMMMMMPPPPOOOOIII! ! ...\n");
- printf(" ........ MMMMMMMMMMMMPPPPPOOOOOOII!! .....\n");
- printf(" ........ MMMMMOOOOOOPPPPPPPPOOOOMII! ...\n");
- printf(" ....... MMMMM.. OPPMMP .,OMI! ....\n");
- printf(" ...... MMMM:: o.,OPMP,.o ::I!! ...\n");
- printf(" .... NNM:::.,,OOPM!P,.::::!! ....\n");
- printf(" .. MMNNNNNOOOOPMO!!IIPPO!!O! .....\n");
- printf(" ... MMMMMNNNNOO:!!:!!IPPPPOO! ....\n");
- printf(" .. MMMMMNNOOMMNNIIIPPPOO!! ......\n");
- printf(" ...... MMMONNMMNNNIIIOO!..........\n");
- printf(" ....... MN MOMMMNNNIIIIIO! OO ..........\n");
- printf(" ......... MNO! IiiiiiiiiiiiI OOOO ...........\n");
- printf(" ...... NNN.MNO! . O!!!!!!!!!O . OONO NO! ........\n");
- printf(" .... MNNNNNO! ...OOOOOOOOOOO . MMNNON!........\n");
- printf(" ...... MNNNNO! .. PPPPPPPPP .. MMNON!........\n");
- printf(" ...... OO! ................. ON! .......\n");
- printf(" ................................\n\n");
- }
- void randompass(char* s, const int len) {
- static const char alphanum[] =
- "0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz";
- int i;
- for (i = 0; i < len; ++i) {
- s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
- }
- s[len] = 0;
- }
- unsigned int BKDRHash(char *str){
- unsigned int seed = 131;
- unsigned int hash = 0;
- unsigned int i = 0;
- char buff[60];
- unsigned int len = 0;
- strcpy(buff, str);
- len = strlen(buff);
- if(len >40)
- len = 40;
- for(i = 0; i < len; (*buff)++, i++)
- {
- hash = (hash * seed) + (*buff);
- }
- return hash;
- }
- void help_() {
- printf("--hash password : hashes a password with the BKDR hash, eg: ./psst --hash qwerty\n");
- printf("--password len : generates a random password, eg: ./psst --password 10\n");
- printf("--help : prints this information\n");
- }
- void handle(int argc, char** argv) {
- char line[124];
- int option = 0;
- int long_index = 0;
- int password = -1;
- char *endptr;
- int hv=-1, pv=-1, tv=-1;
- static struct option long_options[] = {
- {"help", no_argument, 0, 'h' },
- {"password", required_argument, 0, 'p' },
- {"hash", required_argument, 0, 't' },
- {0, 0, 0, 0 }
- };
- while((option = getopt_long(argc, argv, "hp:t:", long_options, &long_index)) != -1) {
- switch (option) {
- case 'h' :
- hv=0;
- break;
- case 'p' :
- password = strtol(optarg, &endptr, 10);
- if ((errno == ERANGE && (password == LONG_MAX || password == LONG_MIN)) || (errno != 0 && password == 0)) {
- printf("error\n");
- exit(EXIT_FAILURE);
- }
- if (endptr == optarg) {
- printf("error\n");
- exit(EXIT_FAILURE);
- }
- if (password>1337) {
- printf("you are too paranoid for me\n");
- exit(EXIT_FAILURE);
- }
- pv=0;
- break;
- case 't' :
- strncpy(line, optarg, sizeof(line));
- tv=0;
- break;
- default:
- printf("invalid command\n");
- exit(EXIT_FAILURE);
- }
- }
- if (!hv) {
- welcome();
- help_();
- } else if(!pv) {
- char *s = malloc(sizeof(char)*password);
- if(s!= NULL) {
- randompass(s,password);
- printf("%s\n", s);
- free(s);
- } else {
- printf("internal error");
- }
- } else if(!tv) {
- printf("%d\n",BKDRHash(line));
- } else {
- welcome();
- help_();
- }
- }
- int main(int argc, char** argv){
- srand(time(NULL));
- handle(argc, argv);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement