author | Markus Bröker<broeker.markus@googlemail.com> |
Sun, 10 Feb 2019 13:17:01 +0100 | |
changeset 173 | 374a86886bc5 |
parent 162 | fad55be2d07c |
permissions | -rw-r--r-- |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
1 |
/** |
77 | 2 |
* md5.c |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
4 |
*/ |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
5 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
6 |
#include <stdio.h> |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
7 |
#include <stdlib.h> |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
8 |
#include <string.h> |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
9 |
#include <openssl/md5.h> |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
10 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
11 |
typedef unsigned char u_char; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
12 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
13 |
int main (int argc, char **argv) |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
14 |
{ |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
15 |
char buffer[80]; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
16 |
char text[80]; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
17 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
18 |
unsigned char *md5_hash; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
19 |
char result[33]; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
20 |
char byte[3]; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
21 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
22 |
int i, j; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
23 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
24 |
if (argc != 2) { |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
25 |
printf ("Usage: %s <text>\n", argv[0]); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
26 |
return EXIT_FAILURE; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
27 |
} |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
28 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
29 |
/* |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
30 |
* MD5 alters the input buffer |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
31 |
*/ |
162
fad55be2d07c
damn strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
148
diff
changeset
|
32 |
strncpy (buffer, argv[1], sizeof (buffer) - 1); |
fad55be2d07c
damn strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
148
diff
changeset
|
33 |
strncpy (text, argv[1], sizeof (text) - 1); |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
34 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
35 |
md5_hash = MD5 ((u_char *) buffer, strlen (buffer), NULL); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
36 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
37 |
for (i = 0, j = 0; i < 16; i++) { |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
38 |
sprintf (byte, "%02x", (md5_hash[i] & 0xFF)); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
39 |
result[j++] = byte[0]; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
40 |
result[j++] = byte[1]; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
41 |
} |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
42 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
43 |
result[j] = 0; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
44 |
printf ("%s: %s\n", text, result); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
45 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
46 |
return EXIT_SUCCESS; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff
changeset
|
47 |
} |