-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptt.c
71 lines (61 loc) · 1.48 KB
/
ptt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <math.h>
char p[12][24] = {
"abcdefghiklnopqrstuwxyzm", // ab
"abcdefghiklopqrstuwxyzmn", // cd
"abcdefghiklpqrstuwxyzmno", // ef
"abcdefghiklqrstuwxyzmnop", // gh
"abcdefghiklrstuwxyzmnopq", // ik
"abcdefghiklstuwxyzmnopqr", // lm
"abcdefghikltuwxyzmnopqrs", // no
"abcdefghikluwxyzmnopqrst", // pq
"abcdefghiklwxyzmnopqrstu", // rs
"abcdefghiklxyzmnopqrstuw", // tu
"abcdefghiklyzmnopqrstuwx", // wx
"abcdefghiklmnopqrstuwxyz" // yz
};
/* void *portaDecipher (char *key, char *out)
{
int i;
int period = strlen(key);
int len = strlen(ct);
for (i = 0; i < len; i++)
{
int j = (strchr(c, key[i % period])-c) / 2; // 0 to 11
int k = (strchr(p[j], ct[i])-p[j]); // 0 to 23
// now 0 to 11 goes to 12 to 23; 12 to 23 goes to 0 to 11
if (k < 12) k+= 12; else k-=12;
out[i] = p[j][k];
}
out[len] = 0;
} */
main(int argc, char **argv)
{
char ct[20];
if (argc != 2) exit (1);
strcpy(ct,argv[1]);
while (1)
{
char pt[20];
int i,len,poss=0;
fscanf(stdin,"%s",pt);
if (feof(stdin)) break;
len = strlen(pt);
for (i = 0; i < len; i++)
{
int s1,s2,a,good=0;
for (a = 0; a < 12; a++)
{
s1 = (strchr(p[a], pt[i]) - p[a]);
s2 = (strchr(p[a], ct[i]) - p[a]);
//if (s1/12 != s2/12 && s1%12 == s2%12) {printf("%d %d\n",i,a); good = 1; }
if (s1/12 != s2/12 && s1%12 == s2%12) good = 1;
}
if (good == 1) poss++;
}
if (poss == len) printf("%s\n",pt);
}
}