diff --git a/Modules/rotormodule.c b/Modules/rotormodule.c index e40615fb8d0..e8fec074832 100644 --- a/Modules/rotormodule.c +++ b/Modules/rotormodule.c @@ -1,6 +1,4 @@ /*********************************************************** -Copyright 1992 by Lance Ellinghouse (lance@markv.com). - Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands. @@ -22,6 +20,19 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +******************************************************************/ +/****************************************************************** +Copyright 1992 by Lance Ellinghouse (lance@markv.com) + +All Rights Reserved + +Permission to use, copy, distribute for any purpose and without fee +is hereby granted, provided that this copyright notice appear in +all copies and that both this copyright notice and this permission +notice appear in supporting documentation. +Permission to make any changes is granted on the basis that all +changes and improvements are also forwarded to Lance Ellinghouse +before distribution. ******************************************************************/ /* This creates an encryption and decryption engine I am calling @@ -35,9 +46,19 @@ Rotor Module: Rotor Objects: +- ro.setkey('string') -> None (resets the key as defined in newrotor(). - ro.encrypt('string') -> encrypted string - ro.decrypt('encrypted string') -> unencrypted string +- ro.encryptmore('string') -> encrypted string +- ro.decryptmore('encrypted string') -> unencrypted string + +NOTE: the {en,de}cryptmore() methods use the setup that was + established via the {en,de}crypt calls. They will NOT + re-initalize the rotors unless: 1) They have not been + initalized with {en,de}crypt since the last setkey() call; + 2) {en,de}crypt has not been called for this rotor yet. + NOTE: you MUST use the SAME key in rotor.newrotor() if you wish to decrypt an encrypted string. Also, the encrypted string is NOT 0-127 ASCII. @@ -51,11 +72,14 @@ NOTE: you MUST use the SAME key in rotor.newrotor() #include "modsupport.h" #include #include +#define TRUE 1 +#define FALSE 0 typedef struct { OB_HEAD int seed[3]; short key[5]; + int isinited; int size; int size_mask; int rotors; @@ -79,6 +103,7 @@ rotorobject *r; r->seed[0] = r->key[0]; r->seed[1] = r->key[1]; r->seed[2] = r->key[2]; + r->isinited = FALSE; } /* Return the next random number in the range [0.0 .. 1.0) */ @@ -120,6 +145,7 @@ static short r_rand(r,s) rotorobject *r; short s; { + /*short tmp = (short)((int)(r_random(r) * (float)32768.0) % 32768);*/ short tmp = (short)((short)(r_random(r) * (float)s) % s); return tmp; } @@ -360,6 +386,7 @@ static void RTR_init(r) r->advances[i] = (1+(2*(r_rand(r,r->size/2)))); RTR_permute_rotor(r,&(r->e_rotor[(i*r->size)]),&(r->d_rotor[(i*r->size)])); } + r->isinited = TRUE; } /*(defun RTR-advance () @@ -497,13 +524,15 @@ static unsigned char RTR_d_char(r, c) (let ((fc (following-char))) (insert-char (RTR-e-char fc) 1) (delete-char 1))))))*/ -static void RTR_e_region(r, beg, len) +static void RTR_e_region(r, beg, len, doinit) rotorobject *r; unsigned char *beg; int len; + int doinit; { register int i; - RTR_init(r); + if (doinit || r->isinited == FALSE) + RTR_init(r); for (i=0;iisinited == FALSE) + RTR_init(r); for (i=0;i