annotate PsiCLASS-1.0.2/samtools-0.1.19/misc/md5fa.c @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #include <stdio.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #include <zlib.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 #include "md5.h"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #include "kseq.h"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6 #define HEX_STR "0123456789abcdef"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 KSEQ_INIT(gzFile, gzread)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 static void md5_one(const char *fn)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 MD5_CTX md5_one, md5_all;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 int l, i, k;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 gzFile fp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 kseq_t *seq;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 unsigned char unordered[16], digest[16];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 for (l = 0; l < 16; ++l) unordered[l] = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 fp = strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 if (fp == 0) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 fprintf(stderr, "md5fa: %s: No such file or directory\n", fn);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 exit(1);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 MD5Init(&md5_all);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 seq = kseq_init(fp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 while ((l = kseq_read(seq)) >= 0) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 for (i = k = 0; i < seq->seq.l; ++i) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 if (islower(seq->seq.s[i])) seq->seq.s[k++] = toupper(seq->seq.s[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 else if (isupper(seq->seq.s[i])) seq->seq.s[k++] = seq->seq.s[i];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 MD5Init(&md5_one);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 MD5Update(&md5_one, (unsigned char*)seq->seq.s, k);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 MD5Final(digest, &md5_one);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 for (l = 0; l < 16; ++l) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 printf("%c%c", HEX_STR[digest[l]>>4&0xf], HEX_STR[digest[l]&0xf]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 unordered[l] ^= digest[l];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 printf(" %s %s\n", fn, seq->name.s);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 MD5Update(&md5_all, (unsigned char*)seq->seq.s, k);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 MD5Final(digest, &md5_all);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 kseq_destroy(seq);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 for (l = 0; l < 16; ++l)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 printf("%c%c", HEX_STR[digest[l]>>4&0xf], HEX_STR[digest[l]&0xf]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 printf(" %s >ordered\n", fn);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 for (l = 0; l < 16; ++l)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 printf("%c%c", HEX_STR[unordered[l]>>4&0xf], HEX_STR[unordered[l]&0xf]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 printf(" %s >unordered\n", fn);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 int main(int argc, char *argv[])
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 int i;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 if (argc == 1) md5_one("-");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 else for (i = 1; i < argc; ++i) md5_one(argv[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58 }