Mercurial > cpython-lru_cache-weakref
annotate Modules/rotormodule.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 9d6e97d66670 |
| children | 8783cfdc7c6f |
| rev | line source |
|---|---|
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
2 Copyright 1994 by Lance Ellinghouse, |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
3 Cathedral City, California Republic, United States of America. |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
11 supporting documentation, and that the name of Lance Ellinghouse |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
12 not be used in advertising or publicity pertaining to distribution |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
13 of the software without specific, written prior permission. |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
15 LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
17 FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL, |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
18 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
19 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
20 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
21 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
22 |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
23 ******************************************************************/ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 /* This creates an encryption and decryption engine I am calling |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 a rotor due to the original design was a harware rotor with |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 contacts used in Germany during WWII. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 Rotor Module: |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 - rotor.newrotor('key') -> rotorobject (default of 6 rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 - rotor.newrotor('key', num_rotors) -> rotorobject |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 Rotor Objects: |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
36 - ro.setkey('string') -> None (resets the key as defined in newrotor(). |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 - ro.encrypt('string') -> encrypted string |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 - ro.decrypt('encrypted string') -> unencrypted string |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
40 - ro.encryptmore('string') -> encrypted string |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
41 - ro.decryptmore('encrypted string') -> unencrypted string |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
42 |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
43 NOTE: the {en,de}cryptmore() methods use the setup that was |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
44 established via the {en,de}crypt calls. They will NOT |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
45 re-initalize the rotors unless: 1) They have not been |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
46 initalized with {en,de}crypt since the last setkey() call; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
47 2) {en,de}crypt has not been called for this rotor yet. |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
48 |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 NOTE: you MUST use the SAME key in rotor.newrotor() |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 if you wish to decrypt an encrypted string. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 Also, the encrypted string is NOT 0-127 ASCII. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 It is considered BINARY data. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 /* Rotor objects */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
1888
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1855
diff
changeset
|
58 #include "Python.h" |
|
be956b1efb97
* various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents:
1855
diff
changeset
|
59 |
| 2506 | 60 #include "mymath.h" |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
61 |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
62 #define TRUE 1 |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
63 #define FALSE 0 |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 typedef struct { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
66 PyObject_HEAD |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 int seed[3]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 short key[5]; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
69 int isinited; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 int size; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 int size_mask; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 int rotors; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 unsigned char *e_rotor; /* [num_rotors][size] */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 unsigned char *d_rotor; /* [num_rotors][size] */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 unsigned char *positions; /* [num_rotors] */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 unsigned char *advances; /* [num_rotors] */ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
77 } PyRotorObject; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
79 staticforward PyTypeObject PyRotor_Type; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
81 #define PyRotor_Check(v) ((v)->ob_type == &PyRotor_Type) |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 /* |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 This defines the necessary routines to manage rotor objects |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 static void set_seed( r ) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
88 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 r->seed[0] = r->key[0]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 r->seed[1] = r->key[1]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 r->seed[2] = r->key[2]; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
93 r->isinited = FALSE; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 /* Return the next random number in the range [0.0 .. 1.0) */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 static float r_random( r ) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
98 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 int x, y, z; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 float val, term; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 x = r->seed[0]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 y = r->seed[1]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 z = r->seed[2]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 x = 171 * (x % 177) - 2 * (x/177); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 y = 172 * (y % 176) - 35 * (y/176); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 z = 170 * (z % 178) - 63 * (z/178); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 if (x < 0) x = x + 30269; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 if (y < 0) y = y + 30307; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 if (z < 0) z = z + 30323; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 r->seed[0] = x; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 r->seed[1] = y; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 r->seed[2] = z; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 term = (float)( |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 (((float)x)/(float)30269.0) + |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 (((float)y)/(float)30307.0) + |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 (((float)z)/(float)30323.0) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 ); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 val = term - (float)floor((double)term); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 if (val >= 1.0) val = 0.0; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 return val; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 static short r_rand(r,s) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
132 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 short s; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 { |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
135 /*short tmp = (short)((int)(r_random(r) * (float)32768.0) % 32768);*/ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 short tmp = (short)((short)(r_random(r) * (float)s) % s); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 return tmp; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 static void set_key(r, key) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
141 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 char *key; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 { |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1386
diff
changeset
|
144 #ifdef BUGGY_CODE_BW_COMPAT |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1386
diff
changeset
|
145 /* See comments below */ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 int k1=995, k2=576, k3=767, k4=671, k5=463; |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1386
diff
changeset
|
147 #else |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1386
diff
changeset
|
148 unsigned long k1=995, k2=576, k3=767, k4=671, k5=463; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1386
diff
changeset
|
149 #endif |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 int i; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 int len=strlen(key); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 for (i=0;i<len;i++) { |
|
1386
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
153 #ifdef BUGGY_CODE_BW_COMPAT |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
154 /* This is the code as it was originally released. |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
155 It causes warnings on many systems and can generate |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
156 different results as well. If you have files |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
157 encrypted using an older version you may want to |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
158 #define BUGGY_CODE_BW_COMPAT so as to be able to |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
159 decrypt them... */ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 k1 = (((k1<<3 | k1<<-13) + key[i]) & 65535); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 k2 = (((k2<<3 | k2<<-13) ^ key[i]) & 65535); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 k3 = (((k3<<3 | k3<<-13) - key[i]) & 65535); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 k4 = ((key[i] - (k4<<3 | k4<<-13)) & 65535); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 k5 = (((k5<<3 | k5<<-13) ^ ~key[i]) & 65535); |
|
1386
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
165 #else |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
166 /* This code should be more portable */ |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
167 k1 = (((k1<<3 | k1>>13) + key[i]) & 65535); |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
168 k2 = (((k2<<3 | k2>>13) ^ key[i]) & 65535); |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
169 k3 = (((k3<<3 | k3>>13) - key[i]) & 65535); |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
170 k4 = ((key[i] - (k4<<3 | k4>>13)) & 65535); |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
171 k5 = (((k5<<3 | k5>>13) ^ ~key[i]) & 65535); |
|
5a30a4e056e7
Replace <<-13 by >>13. Leave old code in #ifdef BUGGY_CODE_BW_COMPAT.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
172 #endif |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 r->key[0] = (short)k1; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 r->key[1] = (short)(k2|1); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 r->key[2] = (short)k3; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 r->key[3] = (short)k4; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 r->key[4] = (short)k5; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 set_seed(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 /* These define the interface to a rotor object */ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
184 static PyRotorObject * |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
185 PyRotor_New(num_rotors, key) |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 int num_rotors; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 char *key; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
189 PyRotorObject *xp; |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
190 xp = PyObject_NEW(PyRotorObject, &PyRotor_Type); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 if (xp == NULL) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 return NULL; |
|
918
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
193 set_key(xp, key); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 xp->size = 256; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 xp->size_mask = xp->size - 1; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 xp->size_mask = 0; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 xp->rotors = num_rotors; |
|
918
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
199 xp->e_rotor = NULL; |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
200 xp->d_rotor = NULL; |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
201 xp->positions = NULL; |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
202 xp->advances = NULL; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 |
|
918
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
204 xp->e_rotor = |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
205 (unsigned char *)malloc((num_rotors * (xp->size * sizeof(char)))); |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
206 if (xp->e_rotor == (unsigned char *)NULL) |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
207 goto fail; |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
208 xp->d_rotor = |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
209 (unsigned char *)malloc((num_rotors * (xp->size * sizeof(char)))); |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
210 if (xp->d_rotor == (unsigned char *)NULL) |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
211 goto fail; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 xp->positions = (unsigned char *)malloc(num_rotors * sizeof(char)); |
|
918
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
213 if (xp->positions == (unsigned char *)NULL) |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
214 goto fail; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 xp->advances = (unsigned char *)malloc(num_rotors * sizeof(char)); |
|
918
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
216 if (xp->advances == (unsigned char *)NULL) |
|
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
217 goto fail; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 return xp; |
|
918
e43a220c287a
Changes to make it compile under SGI -- revamped new/dealloc a bit.
Guido van Rossum <guido@python.org>
parents:
917
diff
changeset
|
219 fail: |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
220 Py_DECREF(xp); |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
221 return (PyRotorObject *)PyErr_NoMemory(); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 /* These routines impliment the rotor itself */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 /* Here is a fairly sofisticated {en,de}cryption system. It is bassed |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 on the idea of a "rotor" machine. A bunch of rotors, each with a |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 different permutation of the alphabet, rotate around a different |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 amount after encrypting one character. The current state of the |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 rotors is used to encrypt one character. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 The code is smart enought to tell if your alphabet has a number of |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 characters equal to a power of two. If it does, it uses logical |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 operations, if not it uses div and mod (both require a division). |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 You will need to make two changes to the code 1) convert to c, and |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 customize for an alphabet of 255 chars 2) add a filter at the |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 begining, and end, which subtracts one on the way in, and adds one on |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 the way out. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 You might wish to do some timing studies. Another viable |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 alternative is to "byte stuff" the encrypted data of a normal (perhaps |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 this one) encryption routine. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 j' |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 /*(defun RTR-make-id-rotor (rotor) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 "Set ROTOR to the identity permutation" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 (let ((j 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 (while (< j RTR-size) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 (aset rotor j j) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 (setq j (+ 1 j))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 rotor))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 static void RTR_make_id_rotor(r, rtr) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
256 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 unsigned char *rtr; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 register int j; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 register int size = r->size; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 for (j=0;j<size;j++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 rtr[j] = (unsigned char)j; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 /*(defvar RTR-e-rotors |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 (let ((rv (make-vector RTR-number-of-rotors 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 (i 0) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 tr) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 (setq tr (make-vector RTR-size 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 (RTR-make-id-rotor tr) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 (aset rv i tr) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 (setq i (+ 1 i))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 rv) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 "The current set of encryption rotors")*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 static void RTR_e_rotors(r) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
279 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 int i; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 for (i=0;i<r->rotors;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 RTR_make_id_rotor(r,&(r->e_rotor[(i*r->size)])); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 /*(defvar RTR-d-rotors |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 (let ((rv (make-vector RTR-number-of-rotors 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 (i 0) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 tr) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 (setq tr (make-vector RTR-size 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 (setq j 0) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 (while (< j RTR-size) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 (aset tr j j) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 (setq j (+ 1 j))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 (aset rv i tr) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 (setq i (+ 1 i))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 rv) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 "The current set of decryption rotors")*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 static void RTR_d_rotors(r) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
302 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 register int i, j; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 for (i=0;i<r->rotors;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 for (j=0;j<r->size;j++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 r->d_rotor[((i*r->size)+j)] = (unsigned char)j; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 /*(defvar RTR-positions (make-vector RTR-number-of-rotors 1) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 "The positions of the rotors at this time")*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 static void RTR_positions(r) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
315 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 int i; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 for (i=0;i<r->rotors;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 r->positions[i] = 1; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 /*(defvar RTR-advances (make-vector RTR-number-of-rotors 1) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 "The number of positions to advance the rotors at a time")*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 static void RTR_advances(r) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
326 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 int i; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 for (i=0;i<r->rotors;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 r->advances[i] = 1; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 /*(defun RTR-permute-rotor (e d) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 "Permute the E rotor, and make the D rotor its inverse" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 ;; see Knuth for explaination of algorythm. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 (RTR-make-id-rotor e) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 (let ((i RTR-size) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 q j) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 (while (<= 2 i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 (setq q (fair16 i)) ; a little tricky, decrement here |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 (setq i (- i 1)) ; since we have origin 0 array's |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 (setq j (aref e q)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 (aset e q (aref e i)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 (aset e i j) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 (aset d j i)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 (aset e 0 (aref e 0)) ; don't forget e[0] and d[0] |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 (aset d (aref e 0) 0)))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 static void RTR_permute_rotor(r, e, d) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
350 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 unsigned char *e; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 unsigned char *d; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 short i = r->size; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 short q; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 unsigned char j; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 RTR_make_id_rotor(r,e); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 while (2 <= i) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 q = r_rand(r,i); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 i--; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 j = e[q]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 e[q] = (unsigned char)e[i]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 e[i] = (unsigned char)j; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 d[j] = (unsigned char)i; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 e[0] = (unsigned char)e[0]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 d[(e[0])] = (unsigned char)0; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 /*(defun RTR-init (key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 "Given KEY (a list of 5 16 bit numbers), initialize the rotor machine. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 Set the advancement, position, and permutation of the rotors" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 (R16-set-state key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 (let (i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 (setq i 0) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 (aset RTR-positions i (fair16 RTR-size)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 (aset RTR-advances i (+ 1 (* 2 (fair16 (/ RTR-size 2))))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 (message "Initializing rotor %d..." i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 (RTR-permute-rotor (aref RTR-e-rotors i) (aref RTR-d-rotors i)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 (setq i (+ 1 i)))))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 static void RTR_init(r) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
383 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 int i; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 set_seed(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 RTR_positions(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 RTR_advances(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 RTR_e_rotors(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 RTR_d_rotors(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 for(i=0;i<r->rotors;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 r->positions[i] = r_rand(r,r->size); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 r->advances[i] = (1+(2*(r_rand(r,r->size/2)))); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 RTR_permute_rotor(r,&(r->e_rotor[(i*r->size)]),&(r->d_rotor[(i*r->size)])); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 } |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
396 r->isinited = TRUE; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 /*(defun RTR-advance () |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 "Change the RTR-positions vector, using the RTR-advances vector" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 (let ((i 0) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 (temp 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 (if RTR-size-mask |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 (setq temp (+ (aref RTR-positions i) (aref RTR-advances i))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 (aset RTR-positions i (logand temp RTR-size-mask)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 (if (and (>= temp RTR-size) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 (< i (- RTR-number-of-rotors 1))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 (aset RTR-positions (+ i 1) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 (+ 1 (aref RTR-positions (+ i 1))))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 (setq i (+ i 1))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 (setq temp (+ (aref RTR-positions i) (aref RTR-advances i))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 (aset RTR-positions i (% temp RTR-size)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 (if (and (>= temp RTR-size) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 (< i (- RTR-number-of-rotors 1))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 (aset RTR-positions (+ i 1) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 (+ 1 (aref RTR-positions (+ i 1))))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 (setq i (+ i 1))))))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 static void RTR_advance(r) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
421 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 register int i=0, temp=0; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 if (r->size_mask) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 while (i<r->rotors) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 temp = r->positions[i] + r->advances[i]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 r->positions[i] = temp & r->size_mask; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 if ((temp >= r->size) && (i < (r->rotors - 1))) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 r->positions[(i+1)] = 1 + r->positions[(i+1)]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 i++; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 } else { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 while (i<r->rotors) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 temp = r->positions[i] + r->advances[i]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 r->positions[i] = temp%r->size; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 if ((temp >= r->size) && (i < (r->rotors - 1))) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 r->positions[(i+1)] = 1 + r->positions[(i+1)]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 i++; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 /*(defun RTR-e-char (p) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 "Encrypt the character P with the current rotor machine" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
447 (let ((i 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 (if RTR-size-mask |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 (setq p (aref (aref RTR-e-rotors i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 (logand (logxor (aref RTR-positions i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 p) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 RTR-size-mask))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 (setq i (+ 1 i))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 (while (< i RTR-number-of-rotors) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 (setq p (aref (aref RTR-e-rotors i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 (% (logxor (aref RTR-positions i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 p) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 RTR-size))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 (setq i (+ 1 i)))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 (RTR-advance) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 p))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 static unsigned char RTR_e_char(r, p) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
464 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 unsigned char p; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 register int i=0; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 register unsigned char tp=p; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 if (r->size_mask) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 while (i < r->rotors) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 tp = r->e_rotor[(i*r->size)+(((r->positions[i] ^ tp) & r->size_mask))]; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 i++; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 } else { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 while (i < r->rotors) { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
476 tp = r->e_rotor[(i*r->size)+(((r->positions[i] ^ tp) % (unsigned int) r->size))]; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 i++; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 RTR_advance(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 return ((unsigned char)tp); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
483 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 /*(defun RTR-d-char (c) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
485 "Decrypt the character C with the current rotor machine" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 (let ((i (- RTR-number-of-rotors 1))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 (if RTR-size-mask |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
488 (while (<= 0 i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
489 (setq c (logand (logxor (aref RTR-positions i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 (aref (aref RTR-d-rotors i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 c)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 RTR-size-mask)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 (setq i (- i 1))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
494 (while (<= 0 i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
495 (setq c (% (logxor (aref RTR-positions i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
496 (aref (aref RTR-d-rotors i) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
497 c)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 RTR-size)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 (setq i (- i 1)))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 (RTR-advance) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 c))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 static unsigned char RTR_d_char(r, c) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
503 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 unsigned char c; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 register int i=r->rotors - 1; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 register unsigned char tc=c; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
508 if (r->size_mask) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 while (0 <= i) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 tc = (r->positions[i] ^ r->d_rotor[(i*r->size)+tc]) & r->size_mask; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 i--; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 } else { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 while (0 <= i) { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
515 tc = (r->positions[i] ^ r->d_rotor[(i*r->size)+tc]) % (unsigned int) r->size; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
516 i--; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
519 RTR_advance(r); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 return(tc); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
521 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 /*(defun RTR-e-region (beg end key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 "Perform a rotor encryption of the region from BEG to END by KEY" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 (save-excursion |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 (let ((tenth (/ (- end beg) 10))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
527 (RTR-init key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 (goto-char beg) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 ;; ### make it stop evry 10% or so to tell us |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
530 (while (< (point) end) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
531 (let ((fc (following-char))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
532 (insert-char (RTR-e-char fc) 1) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 (delete-char 1))))))*/ |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
534 static void RTR_e_region(r, beg, len, doinit) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
535 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 unsigned char *beg; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
537 int len; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
538 int doinit; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
539 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
540 register int i; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
541 if (doinit || r->isinited == FALSE) |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
542 RTR_init(r); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
543 for (i=0;i<len;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
544 beg[i]=RTR_e_char(r,beg[i]); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
546 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 /*(defun RTR-d-region (beg end key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
549 "Perform a rotor decryption of the region from BEG to END by KEY" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
550 (save-excursion |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
551 (progn |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
552 (RTR-init key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
553 (goto-char beg) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
554 (while (< (point) end) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
555 (let ((fc (following-char))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
556 (insert-char (RTR-d-char fc) 1) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 (delete-char 1))))))*/ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
558 static void RTR_d_region(r, beg, len, doinit) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
559 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
560 unsigned char *beg; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
561 int len; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
562 int doinit; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
563 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
564 register int i; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
565 if (doinit || r->isinited == FALSE) |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
566 RTR_init(r); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 for (i=0;i<len;i++) { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 beg[i]=RTR_d_char(r,beg[i]); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
569 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
570 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
572 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 /*(defun RTR-key-string-to-ints (key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
574 "Convert a string into a list of 4 numbers" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
575 (let ((k1 995) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
576 (k2 576) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
577 (k3 767) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 (k4 671) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
579 (k5 463) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
580 (i 0)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
581 (while (< i (length key)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
582 (setq k1 (logand (+ (logior (lsh k1 3) (lsh k1 -13)) (aref key i)) 65535)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 (setq k2 (logand (logxor (logior (lsh k2 3) (lsh k2 -13)) (aref key i)) 65535)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 (setq k3 (logand (- (logior (lsh k3 3) (lsh k3 -13)) (aref key i)) 65535)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 (setq k4 (logand (- (aref key i) (logior (lsh k4 3) (lsh k4 -13))) 65535)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 (setq k5 (logand (logxor (logior (lsh k5 3) (lsh k5 -13)) (lognot (aref key i))) 65535)) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 (setq i (+ i 1))) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 (list k1 (logior 1 k2) k3 k4 k5)))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 /* This is done in set_key() above */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
591 #if 0 |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 /*(defun encrypt-region (beg end key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
593 "Interactivly encrypt the region" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 (interactive "r\nsKey:") |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 (RTR-e-region beg end (RTR-key-string-to-ints key)))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
596 static void encrypt_region(r, region, len) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
597 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
598 unsigned char *region; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
599 int len; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
600 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
919
diff
changeset
|
601 RTR_e_region(r,region,len,TRUE); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
603 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
604 /*(defun decrypt-region (beg end key) |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
605 "Interactivly decrypt the region" |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 (interactive "r\nsKey:") |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 (RTR-d-region beg end (RTR-key-string-to-ints key)))*/ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
608 static void decrypt_region(r, region, len) |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
609 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 unsigned char *region; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 int len; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
919
diff
changeset
|
613 RTR_d_region(r,region,len,TRUE); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
615 #endif |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 /* Rotor methods */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 static void |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
620 PyRotor_Dealloc(xp) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
621 PyRotorObject *xp; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
623 PyMem_XDEL(xp->e_rotor); |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
624 PyMem_XDEL(xp->d_rotor); |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
625 PyMem_XDEL(xp->positions); |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
626 PyMem_XDEL(xp->advances); |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
627 PyMem_DEL(xp); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
630 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
631 PyRotor_Encrypt(self, args) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
632 PyRotorObject *self; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
633 PyObject * args; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 char *string = (char *)NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 int len = 0; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
637 PyObject * rtn = (PyObject * )NULL; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 char *tmp; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
640 if (!PyArg_Parse(args,"s#",&string, &len)) |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 return NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 if (!(tmp = (char *)malloc(len+5))) { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
643 PyErr_NoMemory(); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 return NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
645 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 memset(tmp,'\0',len+1); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 memcpy(tmp,string,len); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
648 RTR_e_region(self,(unsigned char *)tmp,len, TRUE); |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
649 rtn = PyString_FromStringAndSize(tmp,len); |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
650 free(tmp); |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
651 return(rtn); |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
652 } |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
653 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
654 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
655 PyRotor_EncryptMore(self, args) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
656 PyRotorObject *self; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
657 PyObject * args; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
658 { |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
659 char *string = (char *)NULL; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
660 int len = 0; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
661 PyObject * rtn = (PyObject * )NULL; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
662 char *tmp; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
663 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
664 if (!PyArg_Parse(args,"s#",&string, &len)) |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
665 return NULL; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
666 if (!(tmp = (char *)malloc(len+5))) { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
667 PyErr_NoMemory(); |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
668 return NULL; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
669 } |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
670 memset(tmp,'\0',len+1); |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
671 memcpy(tmp,string,len); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
672 RTR_e_region(self,(unsigned char *)tmp,len, FALSE); |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
673 rtn = PyString_FromStringAndSize(tmp,len); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 free(tmp); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
675 return(rtn); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
676 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
677 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
678 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
679 PyRotor_Decrypt(self, args) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
680 PyRotorObject *self; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
681 PyObject * args; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
682 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 char *string = (char *)NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
684 int len = 0; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
685 PyObject * rtn = (PyObject * )NULL; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
686 char *tmp; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
687 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
688 if (!PyArg_Parse(args,"s#",&string, &len)) |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 return NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 if (!(tmp = (char *)malloc(len+5))) { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
691 PyErr_NoMemory(); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 return NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 memset(tmp,'\0',len+1); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 memcpy(tmp,string,len); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
696 RTR_d_region(self,(unsigned char *)tmp,len, TRUE); |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
697 rtn = PyString_FromStringAndSize(tmp,len); |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
698 free(tmp); |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
699 return(rtn); |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
700 } |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
701 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
702 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
703 PyRotor_DecryptMore(self, args) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
704 PyRotorObject *self; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
705 PyObject * args; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
706 { |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
707 char *string = (char *)NULL; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
708 int len = 0; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
709 PyObject * rtn = (PyObject * )NULL; |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
710 char *tmp; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
711 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
712 if (!PyArg_Parse(args,"s#",&string, &len)) |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
713 return NULL; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
714 if (!(tmp = (char *)malloc(len+5))) { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
715 PyErr_NoMemory(); |
|
919
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
716 return NULL; |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
717 } |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
718 memset(tmp,'\0',len+1); |
|
d3b27fff00b2
New rotor methods: setkey(), encryptmore() and decryptmore().
Guido van Rossum <guido@python.org>
parents:
918
diff
changeset
|
719 memcpy(tmp,string,len); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
720 RTR_d_region(self,(unsigned char *)tmp,len, FALSE); |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
721 rtn = PyString_FromStringAndSize(tmp,len); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 free(tmp); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 return(rtn); |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
726 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
727 PyRotor_SetKey(self, args) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
728 PyRotorObject *self; |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
729 PyObject * args; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
731 char *string; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
732 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
733 if (PyArg_Parse(args,"s",&string)) |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
734 set_key(self,string); |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
735 Py_INCREF(Py_None); |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
736 return Py_None; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
737 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
739 static struct PyMethodDef PyRotor_Methods[] = { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
740 {"encrypt", (PyCFunction)PyRotor_Encrypt}, |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
741 {"encryptmore", (PyCFunction)PyRotor_EncryptMore}, |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
742 {"decrypt", (PyCFunction)PyRotor_Decrypt}, |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
743 {"decryptmore", (PyCFunction)PyRotor_DecryptMore}, |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
744 {"setkey", (PyCFunction)PyRotor_SetKey}, |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
745 {NULL, NULL} /* sentinel */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
746 }; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
747 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
748 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 /* Return a rotor object's named attribute. */ |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
750 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
751 PyRotor_GetAttr(s, name) |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
752 PyRotorObject *s; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 char *name; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 { |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
755 return Py_FindMethod(PyRotor_Methods, (PyObject * ) s, name); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
756 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
757 |
| 2506 | 758 statichere PyTypeObject PyRotor_Type = { |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
759 PyObject_HEAD_INIT(&PyType_Type) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
760 0, /*ob_size*/ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
761 "rotor", /*tp_name*/ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
762 sizeof(PyRotorObject), /*tp_size*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
763 0, /*tp_itemsize*/ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
764 /* methods */ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
765 (destructor)PyRotor_Dealloc, /*tp_dealloc*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
766 0, /*tp_print*/ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
767 (getattrfunc)PyRotor_GetAttr, /*tp_getattr*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
768 0, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
769 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
770 0, /*tp_repr*/ |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
771 0, /*tp_hash*/ |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 }; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
773 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
775 static PyObject * |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
776 PyRotor_Rotor(self, args) |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
777 PyObject * self; |
|
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
778 PyObject * args; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
779 { |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
780 char *string; |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
781 PyRotorObject *r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
782 int len; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
783 int num_rotors; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
784 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
785 if (PyArg_Parse(args,"s#", &string, &len)) { |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
786 num_rotors = 6; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
787 } else { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
788 PyErr_Clear(); |
|
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
789 if (!PyArg_Parse(args,"(s#i)", &string, &len, &num_rotors)) |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
790 return NULL; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
791 } |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
792 r = PyRotor_New(num_rotors, string); |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
793 return (PyObject * )r; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
794 } |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
795 |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
796 static struct PyMethodDef PyRotor_Rotor_Methods[] = { |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
797 {"newrotor", (PyCFunction)PyRotor_Rotor}, |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 {NULL, NULL} /* Sentinel */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 }; |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
800 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
801 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
802 /* Initialize this module. |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
803 This is called when the first 'import rotor' is done, |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
804 via a table in config.c, if config.c is compiled with USE_ROTOR |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
805 defined. */ |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
806 |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
807 void |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
808 initrotor() |
|
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
809 { |
|
1855
9dbdb83d4178
Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
810 PyObject * m; |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
811 |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
812 m = Py_InitModule("rotor", PyRotor_Rotor_Methods); |
|
917
cfdd575efff2
New file rotormodule.c (by Lance Ellinghouse).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
813 } |
