/*
 	NetZero Password Generator
	--------------------------
	missnglnk@efnet
	Greets: tino@efnet

	*** THIS IS FOR EDUCATIONAL PURPOSES ONLY ***
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	char	upasswd[16];
	char	cpasswd[16];
	char	algo_a[14] = "abcdefghijklmn";
	char	algo_b[14] = "?abcdefghijklm";
	char	algo_c[14] = ">?abcdefghijkl";
	char	algo_d[14] = "<>?abcdefghijk";
	char	algo_e[14] = "/<>?abcdefghij";
	char	algo_f[14] = "./<>?abcdefghi";
	char	algo_g[14] = ",./<>?abcdefgh";
	char	algo_h[14] = "\",./<>?abcdefg";
	char	algo_i[14] = ":\",./<>?abcdef";
	char	algo_j[14] = "':\",./<>?abcde";
	char	algo_k[14] = ";':\",./<>?abcd";
	char	algo_l[14] = "|;':\",./<>?abc";
	char	algo_m[14] = "}|;':\",./<>?ab";
	char	algo_n[14] = "{}|;':\",./<>?a";
	char	algo_o[14] = "\{}|;':\",./<>?";
	char	algo_p[14] = "]\{}|;':\",./<>";
	char	algo_q[14] = "[]\{}|;':\",./<";
	char	algo_r[14] = "+[]\{}|;':\",./";
	char	algo_s[14] = "_+[]\{}|;':\",.";
	char	algo_t[14] = ")_+[]\{}|;':\",";
	char	algo_u[14] = "()_+[]\{}|;':\"";
	char	algo_v[14] = "*()_+[]\{}|;':";
	char	algo_w[14] = "&*()_+[]\{}|;'";
	char	algo_x[14] = "^&*()_+[]\{}|;";
	char	algo_y[14] = "%^&*()_+[]\{}|";
	char	algo_z[14] = "$%^&*()_+[]\{}";
	char	algo_0[14] = "QRSTUVWXYZ0123";
	char	algo_1[14] = "PQRSTUVWXYZ012";
	char	algo_2[14] = "OPQRSTUVWXYZ01";
	char	algo_3[14] = "NOPQRSTUVWXYZ0";
	char	algo_4[14] = "MNOPQRSTUVWXYZ";
	char	algo_5[14] = "LMNOPQRSTUVWXY";
	char	algo_6[14] = "KLMNOPQRSTUVWX";
	char	algo_7[14] = "JKLMNOPQRSTUVW";
	char	algo_8[14] = "IJKLMNOPQRSTUV";
	char	algo_9[14] = "HIJKLMNOPQRSTU";
	int	ulen;
	int	i;

	printf("Netzero Password Generator\n");
	printf("Version 0.1\n");
	printf("missnglnk@efnet\n\n");

	if (argc == 3) {
		if ((ulen = strlen(argv[2])) > 14) {
			printf("Password too long. (Greater than 14 characters).\n");
			return -1;
		} else {
			strncpy(upasswd, argv[2], sizeof(upasswd));
		}
	} else {
		printf("%s [username] [password]\n", argv[0]);
		return -1;
	}

	bzero(cpasswd, sizeof(cpasswd));

	for (i = 0; i <= ulen - 1; i++) {
		if (upasswd[i] == 'a') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_a[i]);
		}

		if (upasswd[i] == 'b') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_b[i]);
		}

		if (upasswd[i] == 'c') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_c[i]);
		}

		if (upasswd[i] == 'd') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_d[i]);
		}

		if (upasswd[i] == 'e') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_e[i]);
		}

		if (upasswd[i] == 'f') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_f[i]);
		}

		if (upasswd[i] == 'g') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_g[i]);
		}

		if (upasswd[i] == 'h') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_h[i]);
		}

		if (upasswd[i] == 'i') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_i[i]);
		}

		if (upasswd[i] == 'j') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_j[i]);
		}

		if (upasswd[i] == 'k') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_k[i]);
		}

		if (upasswd[i] == 'l') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_l[i]);
		}

		if (upasswd[i] == 'm') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_m[i]);
		}

		if (upasswd[i] == 'n') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_n[i]);
		}

		if (upasswd[i] == 'o') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_o[i]);
		}

		if (upasswd[i] == 'p') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_p[i]);
		}

		if (upasswd[i] == 'q') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_q[i]);
		}

		if (upasswd[i] == 'r') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_r[i]);
		}

		if (upasswd[i] == 's') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_s[i]);
		}

		if (upasswd[i] == 't') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_t[i]);
		}

		if (upasswd[i] == 'u') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_u[i]);
		}

		if (upasswd[i] == 'v') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_v[i]);
		}

		if (upasswd[i] == 'w') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_w[i]);
		}

		if (upasswd[i] == 'x') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_x[i]);
		}

		if (upasswd[i] == 'y') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_y[i]);
		}

		if (upasswd[i] == 'z') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_z[i]);
		}

		if (upasswd[i] == '0') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_0[i]);
		}

		if (upasswd[i] == '1') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_1[i]);
		}

		if (upasswd[i] == '2') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_2[i]);
		}

		if (upasswd[i] == '3') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_3[i]);
		}

		if (upasswd[i] == '4') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_4[i]);
		}

		if (upasswd[i] == '5') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_5[i]);
		}

		if (upasswd[i] == '6') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_6[i]);
		}

		if (upasswd[i] == '7') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_7[i]);
		}

		if (upasswd[i] == '8') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_8[i]);
		}

		if (upasswd[i] == '9') {
			sprintf(cpasswd, "%s%c", cpasswd, algo_9[i]);
		}
	}

	printf("Username:\t:%s@netzero.net\n", argv[1]);
	printf("Password:\t0%s1\n\n", cpasswd);
	return -1;
}
