-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptestfix.c
75 lines (65 loc) · 1.71 KB
/
ptestfix.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
72
73
74
75
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <math.h>
char c[] = "abcdefghiklmnopqrstuwxyz";
char p[12][25] = {
"abcdefghiklmnopqrstuwxyz", // ab
"abcdefghiklmopqrstuwxyzn", // cd
"abcdefghiklmpqrstuwxyzno", // ef
"abcdefghiklmqrstuwxyznop", // gh
"abcdefghiklmrstuwxyznopq", // ik
"abcdefghiklmstuwxyznopqr", // lm
"abcdefghiklmtuwxyznopqrs", // no
"abcdefghiklmuwxyznopqrst", // pq
"abcdefghiklmwxyznopqrstu", // rs
"abcdefghiklmxyznopqrstuw", // tu
"abcdefghiklmyznopqrstuwx", // wx
"abcdefghiklmznopqrstuwxy" // 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[25];
if (argc != 2) exit (1);
strcpy(ct,argv[1]);
while (1)
{
char pt[25],px[25];
int i,len,poss=0;
fscanf(stdin,"%s",pt);
if (feof(stdin)) break;
if (strlen(ct) != strlen(pt)) continue;
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])/12;
s2 = (strchr(p[a], ct[i]) - p[a])/12;
if (s1 != s2) good = 1; */
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) good = a+1;
}
if (good > 0) { poss++; px[i] = c[(good-1)*2]; }
}
if (poss == len) { printf("%s %s ",ct,pt); for (i = 0; i < len; i++) printf("%c",px[i]); printf("\n"); }
}
}