Jump to content

The ISAAC cipher: Difference between revisions

m
→‎{{header|Modula-2}}: Some corrections i optimizations based on the C version.
(Dialects of BASIC moved to the BASIC section.)
m (→‎{{header|Modula-2}}: Some corrections i optimizations based on the C version.)
Line 3,272:
TMode = (iEncrypt, iDecrypt);
TString = ARRAY [0 .. MaxStrLength - 1] OF CHAR;
THexString = ARRAY [0 .. 2 * MaxStrLength - 1] OF CHAR;
TCardIndexedFrom0To7 = ARRAY [0 .. 7] OF CARDINAL;
 
Line 3,282 ⟶ 3,283:
XorPlainText: TString = '';
ModPlainText: TString = '';
HexText: TStringTHexString;
Mode: TMode = iEncrypt;
HexText: TString;
 
(* ISAAC globals *)
(* external results *)
RandRsl: ARRAY [0 .. 256255] OF CARDINAL;
RandCnt: CARDINAL;
 
(* internal state *)
MM: ARRAY [0 .. 256255] OF CARDINAL;
AA: CARDINAL = 0;
BB: CARDINAL = 0;
Line 3,378:
PROCEDURE SeedIsaac(Seed: ARRAY OF CHAR; Flag: BOOLEAN);
VAR
I, MSeedLength: CARDINAL;
BEGIN
FOR I := 0 TO 255 DO
MM[I] := 0;
END;
MSeedLength := Length(Seed);
FOR I := 0 TO 255 DO
(* In case seed has less than 256 elements *)
IF I > MSeedLength THEN
RandRsl[I] := 0
ELSE
Line 3,439:
OrdMsgI: SHORTCARD;
BEGIN
Assign(''Msg, Destination);
FOR I := 0 TO Length(Msg) - 1 DO
OrdMsgI := ORD(Msg[I]);
Append(Destination[I] := CHR(GetRandomChar() BXOR OrdMsgI), Destination);
END;
END Vernam;
Line 3,475:
I: CARDINAL;
BEGIN
Assign(''Msg, Destination);
FOR I := 0 TO Length(Msg) - 1 DO
Append(Destination[I] := Caesar(M, Msg[I], GetRandomChar(), 95, ' '), Destination);
END;
END Vigenere;
Line 3,485:
SeedIsaac(Key, TRUE);
(* (2) Encryption *)
Mode := iEncrypt;
(* (a) XOR (Vernam) *)
Vernam(Msg, XorCipherText);
(* (b) MOD (Vigenere) *)
Vigenere(Msg, ModeiEncrypt, ModCipherText);
(* (3) Decryption *)
Mode := iDecrypt;
SeedIsaac(Key, TRUE);
(* (a) XOR (Vernam) *)
Vernam(XorCipherText, XorPlainText);
(* (b) MOD (Vigenere) *)
Vigenere(ModCipherText, ModeiDecrypt, ModPlainText);
(* program output *)
WriteString('Message: '); WriteString(Msg); WriteLn;
512

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.