SWAGOLX.EXE (c) 1993 GDSOFT ALL RIGHTS RESERVED 00018 FILE & ENCRYPTION ROUTINES 1 05-28-9313:40ALL SWAG SUPPORT TEAM CHECKSUM.PAS IMPORT 15 e├ÿ% (*π> I finished Programming a Program in turbo pascal 7, and as some sharewareπ> Programs like RemoteAccess, Fastecho and more i want my Program to use aπ> KEY File to know if the Program is registered or not (i will supply a keyπ> For every sysop according to his bbs name and his name), any examples toπ> do such a Procedure?ππYou could do like I did in Terminate, make a big KeyFile around 4-8k andπincluded all kind of checksums calculated on crc-sums and the name etc.ππCalculate the Crc-sums in different ways, use always the GlobalChecksum to findπout if there has been no errors in the File. If error in the global checksum:ππ SetFAttr(keyFile,Archive) { if the File has been set to readonly }π Erase(keyFile,archive)ππAsk user to install a new copy of the keyFile.ππThen somebody has changed it or an error has occured.ππThe next things is to use a different checksum For each release you make ofπyour Program, then people will get annoyed over waiting For a new pirate keyπand hopefully will send you some money.πThe cracker cannot calculate the checksum if you have no code in the Program,πbut he can crack the current version, but if you release a new version often,πpeople will get tired of that and pay. A checksum can be calculated in manyπdifferent ways like below:π*)πVarππ KeyRec : Recordπ Crc : Array[1..100] of LongInt;π Name : String[80];π GlobalChecksum;π end;ππVarπ Sum : LongInt;π X : Word;ππbeginπ Sum := 0;π For x := 1 to Sizeof(KeyRec) Doπ Inc(Sum, Mem[Seg(KeyRec) : Seg(KeyRec) + x]);π { This will add all ascii values to crc, the cracker will prop. findπ this out, but if you then : }π Dec(Sum,3248967);π { How should he find out if there is no code in your Program at the }π { present version }πend.π 2 05-28-9313:40ALL SWAG SUPPORT TEAM COPYINC.PAS IMPORT 21 e├ßa { COPYINC.PAS Author: Trevor J Carlsenπ PO Box 568π Port Hedland 6721π Western AustraliaπππSYNTAX: copyinc Filenameππwhere Filename is the name of a Text File you wish to create that will be usedπas an include File in a Turbo Pascal Program.ππThis Program creates a Text File in the formatππ Constπ RegStr ='This Program is an unregistered copy';π CodeStr =π #125#34#139#139#74#71#94#61#44#78#65#155#158#132#62#136#141#140#84+π #34#155#63#38#46#89#84#93#57#153#51#83#112#72#36#138#93;π keyval = 1234567890;ππThe Text File that was used by COPYINC to create the above include File wouldπhave looked like thisππp:\prog\freeload.incπThis Program is an unregistered copyπRegStr =πCodeStr =π1234567890ππHere is another example. This was the include File -ππ Constπ ChkStr : String ='This Program is registered to';π CodeChkStr : String =π #32#153#90#34#133#140#42#129#150#50#81#36#83#36#133#154#52#76#75+π #129#45#93#77#44#83#149#157#71#95#225;π keyval = 1234567890;ππand the Text File used by COPYINC -ππp:\prog\registed.incπThis Program is registered to πChkStr : String =πCodeChkStr : String =π1234567890πππThe Text File must always consist of five lines that areπ 1. The name of the include File to be created.π 2. The plain Text.π 3. The name of the plain Text Constant along With its syntax.π 4. The name and syntax of the coded Text Constant.π 5. A key value. Any number in the LongInt range is valid.πππ}ππUsesπ endecode; { my encryption Unit }ππConstπ hash = '#';πVarπ f : Text;π params : Text;π keyval : LongInt;π notice,π fname,π CodeStr,π CodeVar,π PlainVar: String;π x : Word;ππbeginπ assign(params,ParamStr(1));π reset(params);π readln(params,fname);π readln(params,notice);π readln(params,PlainVar);π readln(params,CodeVar);π readln(params,keyval);π CodeStr := EncryptStr(keyval,notice);π notice := ' '+ PlainVar + #39 + notice + #39#59;π assign(f,fname);π reWrite(f);π Writeln(f,'Const');π Writeln(f,notice);π Writeln(f,' ',CodeVar);π Write(f,' ');π For x := 1 to length(CodeStr) do beginπ if x mod 20 = 0 then beginπ Writeln(f,'+');π Write(f,' ');π end;π Write(f,'#',ord(CodeStr[x]));π end;π Writeln(f,';');π Writeln(f,' keyval = ',keyval,#59);π Writeln(f);π close(f);πend.ππ 3 05-28-9313:40ALL SWAG SUPPORT TEAM ENCRYPT.PAS IMPORT 65 e├Γ {$A+,B-,D-,E+,F-,G+,I+,L-,N-,O-,R-,S-,V-,X+}π{$M 4048,0,131040}πProgram encrypt;ππ{ Author Trevor J Carlsen - released into the public domain 1992 }π{ PO Box 568 }π{ Port Hedland }π{ Western Australia 6721 }π{ Voice +61 91 73 2026 Data +61 91 73 2569 }π{ FidoNet 3:690/644 }ππ{ Syntax: encrypt /p=PassWord /k=KeyFile /f=File }π{ Example - }π{ encrypt /p=billbloggs /k=c:\command.com /f=p:\prog\anyFile.pas }ππ{ PassWord can be any alpha-numeric sequence of AT LEAST four }π{ Characters. }ππ{ KeyFile is the full path of any File on the system that this }π{ Program runs on. This File, preferably a large one, must not }π{ be subject to changes. This is critical as it is used as a }π{ pseudo "one time pad" style key and the slightest change will }π{ render decryption invalid. }ππ{ File is the full path of the File to be encrypted or decrypted.}ππ{ notes: Running Encrypt a second time With exactly the same parameters }π{ decrypts an encrypted File. For total security the keyFile }π{ can be stored separately on a floppy. Without this keyFile or }π{ knowledge of its contents it is IMPOSSIBLE to decrypt the }π{ encrypted File. }ππ{ Parameters are Case insensitive and may be in any order and }π{ may not contain any Dos separator Characters. }ππConstπ BufferSize = 65520;π Renamed : Boolean = False;ππTypeπ buffer_ = Array[0..BufferSize - 1] of Byte;π buffptr = ^buffer_;π str80 = String[80];ππVarπ OldExitProc : Pointer;π KeyFile,π OldFile,π NewFile : File;π KeyBuffer,π Buffer : buffptr;π KeyFileSize,π EncFileSize : LongInt;π PassWord,π KFName,π FFName : str80;ππProcedure Hash(p : Pointer; numb : Byte; Var result: LongInt);π { When originally called numb must be equal to sizeof }π { whatever p is pointing at. if that is a String numb }π { should be equal to length(the_String) and p should be } π { ptr(seg(the_String),ofs(the_String)+1) }π Varπ temp,π w : LongInt;π x : Byte;ππ beginπ temp := LongInt(p^); RandSeed := temp;π For x := 0 to (numb - 4) do beginπ w := random(maxint) * random(maxint) * random(maxint);π temp := ((temp shr random(16)) shl random(16)) +π w + MemL[seg(p^):ofs(p^)+x];π end;π result := result xor temp;π end; { Hash }ππProcedure NewExitProc; Far;π { Does the "housekeeping" necessary on Program termination }π Var code : Integer;π beginπ ExitProc := OldExitProc; { Reset Exit Procedure Pointer to original }π Case ExitCode ofπ 0: Writeln('Successfully encrypted or decrypted ',FFName);π 1: beginπ Writeln('This Program requires 3 parameters -');π Writeln(' /pPassWord');π Writeln(' /kKeyFile (full path and name)');π Write (' /fFile (The full path and name of the File');π Writeln(' to be processed)');π Writeln;π Write ('These parameters can be in any order, are Case,');π Writeln(' insensitive, and may not contain any spaces.');π end;π 2: Writeln('Could not find key File');π 3: Writeln('Could not rename and/or open original File');π 4: Writeln('Could not create encrypted File');π 5: Writeln('I/O error during processing - could not Complete');π 6: Writeln('Insufficient memory available');π 7: beginπ Writeln('Key File is too small - aborted');π Writeln;π Writeln(' Key File must be at least as large as the buffer size ');π Write (' or the size of the File to be encrypted, whatever is the');π Writeln(' smaller.');π end;π 8: Writeln('PassWord must consist of at least 4 Characters');π else { any other error }π Writeln('Aborted With error ',ExitCode);π end; { Case }π if Renamed and (ExitCode <> 0) thenπ Writeln(#7'WARNinG: original File''s name is now TEMP.$$$');π {$I-}π close(KeyFile); Code := Ioresult;π close(NewFile); Code := Ioresult;π close(OldFile); Code := Ioresult;π if ExitCode = 0 thenπ Erase(OldFile); Code := Ioresult;π {$I+}π end; { NewExitProc }πππFunction Str2UpCase(Var S: String): String;π { Converts a String S to upper Case. Valid For English. }π Varπ x : Byte;π beginπ Str2UpCase[0] := S[0];π For x := 1 to length(S) doπ Str2UpCase[x] := UpCase(S[x]);π end; { Str2UpCase }ππProcedure Initialise;π Varπ CommandLine : String;π FPos,FLen,π KPos,KLen,π PPos,PLen : Byte;ππ Procedure AllocateMemory(Var p: buffptr; size: LongInt);π beginπ if size < BufferSize then beginπ if MaxAvail < size then halt(6);π GetMem(p,size);π endπ else beginπ if MaxAvail < BufferSize then halt(6);π new(p);π end;π end; { AllocateMemory }ππ beginπ FillChar(OldExitProc,404,0); { Initialise all global Variables }π FillChar(PassWord,243,32);π ExitProc := @NewExitProc; { Set up new Exit Procedure }π if ParamCount <> 3 then halt(1);π CommandLine := String(ptr(PrefixSeg,$80)^)+' '; { Add trailing space }π CommandLine := Str2UpCase(CommandLine); { Convert to upper Case }π PPos := pos('/P=',CommandLine); { Find passWord parameter }π KPos := pos('/K=',CommandLine); { Find keyFile parameter }π FPos := pos('/F=',CommandLine); { Find Filename For encryption}π if (PPos = 0) or (KPos = 0) or (FPos = 0) then Halt(1);π FFName := copy(CommandLine,FPos+3,80);π FFName[0] := chr(pos(' ',FFName)-1); { Correct String length }π KFName := copy(CommandLine,KPos+3,80);π KFName[0] := chr(pos(' ',KFName)-1);π PassWord := copy(CommandLine,PPos+3,80);π PassWord[0] := chr(pos(' ',PassWord)-1);π if length(PassWord) < 4 then halt(8);π { Create a random seed value based on the passWord }π Hash(ptr(seg(PassWord),ofs(PassWord)+1),length(PassWord),RandSeed);π assign(OldFile,FFName);π {$I-}π rename(OldFile,'TEMP.$$$');π if Ioresult <> 0 thenπ halt(3)π elseπ renamed := True;π assign(OldFile,'TEMP.$$$');π reset(OldFile,1);π if Ioresult <> 0 then halt(3);π assign(NewFile,FFName);π reWrite(NewFile,1);π if Ioresult <> 0 then halt(4);π assign(KeyFile,KFName);π reset(KeyFile,1);π if Ioresult <> 0 then halt(2);π EncFileSize := FileSize(OldFile);π KeyFileSize := FileSize(KeyFile);π if KeyFileSize > EncFileSize thenπ KeyFileSize := EncFileSize;π if Ioresult <> 0 then halt(5);π {$I+}π if (KeyFileSize < BufferSize) and (KeyFileSize < EncFileSize) thenπ halt(7);π AllocateMemory(buffer,EncFileSize);π AllocateMemory(KeyBuffer,KeyFileSize);π end; { Initialise }ππProcedure Main;π Varπ BytesRead : Word;π finished : Boolean;ππ Procedure CodeBuffer(number: Word);π { This is the actual encryption/decryption engine }π Var x : Word;π beginπ For x := 0 to number - 1 doπ buffer^[x] := buffer^[x] xor KeyBuffer^[x] xor Random(256);π end; { CodeBuffer }ππ beginπ {$I-}π finished := False;π Repeatπ BlockRead(OldFile,buffer^,BufferSize,BytesRead);π if Ioresult <> 0 then halt(5);π if (FilePos(KeyFile) + BytesRead) > KeyFileSize thenπ seek(KeyFile,0);π BlockRead(KeyFile,KeyBuffer^,BytesRead,BytesRead);π if Ioresult <> 0 then halt(5);π CodeBuffer(BytesRead);π finished := BytesRead < BufferSize;π BlockWrite(NewFile,buffer^,BytesRead);π Until finished;π end; { Main }ππbeginπ Initialise;π Main;πend.π 4 05-28-9313:40ALL SWAG SUPPORT TEAM ENCRYPT1.PAS IMPORT 6 e├┴ Function EncryptDecrypt(S : String : K : String) : String;πVarπ I,Q : Integer;π O : String[255];πbeginπ Q := 1;π O := "";π For I := 1 to Length(S) Doπ beginπ O := O + Chr(Ord(S[I]) Xor Ord(K[Q]));π Inc(Q); If Q > Length(K) Then Q := 1;π end;π EncryptDecrypt := O;πend;ππA couple of thoughts on this.ππ1. If K is short then the decryption is very easy.π2. The routine would be VERY slow as it is using String concatenation. Itπ would be MUCH faster if the O := "" line was changed to O[0] := S[0] andπ the O := O + ... line was replaced With -π O[I] := ...ππTeeCeeπ 5 05-28-9313:40ALL SWAG SUPPORT TEAM ENCRYPT2.PAS IMPORT 10 e├Tw {The following very simple routine will encrypt and decrypt a Text File a lineπat a time. The CR/LF is left unencrypted and the algorithm ensures that noπencrypted Character can be < asciiz 127 *provided that* the Text For encryptingπhas no hi-bit Characters.ππObviously this is just a skeleten example (untested) With no error checking butπit should demonstrate what you need to do. After encrypting Text just reverseπthe parameters and run the Program again to decrypt the encrypted Text.π}πProgram encrypt_Text;ππVarπ inText,π outText : Text;π st : String;ππFunction ConvertTxt(s: String): String;π Var x : Byte;π beginπ ConvertTxt[0] := s[0];π For x := 1 to length(s) doπ ConvertTxt[x] := chr(ord(s[x]) xor (Random(128) or 128));π end; { ConvertTxt }ππbeginπ RandSeed := 1234567;{ set to whatever value you wish - this is your "key" }π assign(inText,ParamStr(1));π reset(inText);π assign(outText,ParamStr(2));π reWrite(outText);π While not eof(inText) do beginπ readln(inText,st);π Writeln(outText,ConvertTxt(st));π end;π close(inText);π close(outText);πend.π 6 05-28-9313:40ALL SWAG SUPPORT TEAM ENCRYPT3.PAS IMPORT 12 e├└╦ { JL> I'm writing a Program to set and test passWords. I imagine you saw it inπ JL> PASCAL echo. Well, I want to know if there is an easier way to encrypt aπ JL> File then to assign a different Character to each letter. This is theπ JL> only way that I can think of to do this.ππ JL> 'A':= '^';π JL> 'B':= 'q';ππWhat you suggest isn't so much encryption as it is a substitution cypher. Theπfollowing is more of an *encryption*:π}ππFunction Crypt(S : String) : String;π(* xor can be used to *toggle* values. In this Case it is toggling *)π(* Character of the String based on its postion in the String. This *)π(* ensures that the mask is always known For the pupose of decoding. *)π Varπ i : Byte;π beginπ For i := 1 to Length(S) Doπ S[i] := Char(ord(S[i]) xor i);π Crypt := S;π end;ππVarπ TestS : String;π TestMask : Byte;ππbeginπ TestS := 'This is a test 1234567890 !@$%';π Write('original: ');π Writeln(TestS);ππ TestS := Crypt(TestS);π Write('Encrypt : ');π Writeln(TestS);ππ TestS := Crypt(TestS);π Write('Decrypt : ');π Writeln(TestS);πend.ππ{Please note that this was a quickie and not fully tested and thereForeπcannot be guaranteed to be perfect. <grin> But it ought to give you aπslightly different perspective and help you see alternate approaches toπthe problem.π}π 7 05-28-9313:40ALL SWAG SUPPORT TEAM ENCRYPT4.PAS IMPORT 12 e├i_ { JC> I was wondering what Format you Programmers out there use to makeπ JC> registration codes. I was fooling around With a letter standing Forπ JC> another letter but thats too simple. How can I go about writingπ JC> bullet proof (or at least bullet resistant) registration codes. BTW,π JC> this is not an over the modem Type Program. if you understand whatπ JC> I'm TRYinG to say, I wopuld RealLY appreciate a response. Thanks aπ JC> lot!!!π}πππProgram RegCode;ππUses Crt;ππVarπ ch : Char;π Name : String;ππFunction MakeRegCode(S:String): LongInt;ππVarπ I: LongInt;π B: Byte;ππbeginπ I:=0; { Could make this something else if you want it more random looking }π For B:=1 to Length(S)π Do I:=I+ord(S[B]); { Could make it ord(S[B]+SomeValue) to make it moreπ interesting }π MakeRegCode:=I;πend;ππbeginππ Writeln;π Writeln;π Write('Enter SysOp Name : ');π Readln(Name);π Writeln;π Writeln('The resultant code was ',MakeRegCode(Name));π Writeln;π ch:=ReadKey;ππend.πππ{You can also add a BBS Name or a City or anything else you want. just keep onπadding it to the I Var in the MakeRegCode proc. to check to see if a reg codeπis valid, just Compare the registration code he already has (in a cfg Fileπcomewhere I assume) With the one generated this part of code. if they match,πthen is is a good code... if not... then he didn't register.π}π 8 05-28-9313:40ALL SWAG SUPPORT TEAM ENDECODE.PAS IMPORT 31 e├µ. Unit endecode;π { Simple encryption/decryption routines. }ππInterfaceππTypeπ stArray = Array[0..255] of Byte;ππFunction Key(Var s): LongInt;πFunction EncryptStr(key : LongInt; s: String): String;πFunction DecryptStr(key : LongInt; s: String): String;ππImplementationππFunction MakeCodeStr(key : LongInt; Var s): String;π {--------------------------------------------------------}π { Creates a "randomly" Constructed String of a similar }π { length as the String which is to be encrypted. A }π { LongInt key is used to permit "passWord" Type }π { encryption. This key may be passed as a literal or }π { some passWord used to calculate it. Using this key, }π { the last Character of the String to be encrypted and }π { the length of the String, a "code String" is produced. }π { This code String is then xord With the original String }π { to produce the encrypted String. The last Character }π { however must be treated differently so that it can be }π { easily decoded in order to reproduce the coded String }π { used For decoding. This is done by xoring it With the }π { length of the String. to decrypt a String the last }π { Character must be decoded first and then the key coded }π { String produced in order to decrypt each Character. }π {--------------------------------------------------------}ππ Varπ x : Word;π len : Byte Absolute s;π st : Array[0..255] of Byte Absolute s;ππ beginπ RandSeed := (key * len) div st[len];π {This ensures that no two code Strings will be similar UNLESS they areπ of identical length, have identical last Characters and the sameπ key is used.}π MakeCodeStr[0] := chr(len);π For x := 1 to len doπ MakeCodeStr[x] := chr(32 + Random(95));π {Keeping the Character between 32 and 127 ensures that the high bitπ is never set on the original encrypted Character and thereFore allowsπ this to be used as flag to indicate that the coded Char was < #32.π This will then permit the encrypted String to be printed without fearπ of having embedded control codes play havoc With the Printer.}π end;ππFunction Key(Var s): LongInt;π { Creates a key For seeding the random number generator. st can be aπ passWord }π Varπ x : Byte;π temp : LongInt;π c : Array[1..64] of LongInt Absolute s;π len : Byte Absolute s;π beginπ temp := 0;π For x := 1 to len div 4 doπ temp := temp xor c[x];π Key := Abs(temp);π end;ππFunction EncryptStr(key : LongInt; s: String): String;π Varπ cnt,x : Byte;π len : Byte Absolute s;π st : Array[0..255] of Byte Absolute s;π CodeStr : stArray;π temp : String Absolute CodeStr;π beginπ temp := MakeCodeStr(key,st);π EncryptStr[0] := chr(len);π EncryptStr[len]:= chr(st[len]);π For x := 1 to len-1 do beginπ cnt := st[x] xor CodeStr[x];π inc(cnt,128 * ord(cnt < 32));π EncryptStr[x]:= chr(cnt);π end; { For }π cnt := st[len] xor (len and 127);π inc(cnt,128 * ord(cnt < 32));π EncryptStr[len]:= chr(cnt);π end;ππFunction DecryptStr(key : LongInt; s: String): String;π Varπ cnt,x : Byte;π st : stArray Absolute s;π len : Byte Absolute s;π CodeStr : stArray;π temp : String Absolute CodeStr;π ch : Char;π beginπ cnt := st[len] and 127;π st[len] := cnt xor len;π temp := MakeCodeStr(key,st);π DecryptStr[0]:= chr(len);π DecryptStr[len]:= chr(st[len]);π For x := 1 to len-1 do beginπ cnt := st[x];π dec(cnt,128 * ord(st[x] > 127));π DecryptStr[x] := chr(cnt xor CodeStr[x]);π end; { For }π end;ππend.π 9 05-28-9313:40ALL SWAG SUPPORT TEAM HASH.PAS IMPORT 28 e├¬Å Unit Hash;ππ{***************************************************************************π * *π * Copyright 1989 Trevor J Carlsen *π * All rights reserved *π * Rovert Software Consulting Services *π * PO Box 568 *π * Port Hedland Western Australia 6721 *π * Telephone (091) 732026 or (091) 732569 *π * *π ***************************************************************************}ππInterfaceππUses Strings,π sundry;ππFunction hashcode(st : String; Var nwd : Word): Word;ππImplementationππFunction MakeCodeStr(key : LongInt; st : String): String;π Varπ x : Word;π len : Byte Absolute st;π beginπ RandSeed := (key * len) div ord(st[len]);π MakeCodeStr[0] := st[0];π For x := 1 to len doπ MakeCodeStr[x] := chr(Random(255));π end;ππFunction Key(st: String): LongInt;π Varπ len : Byte Absolute st;π x,y : Byte;π temp : LongInt;π tempst : Array[0..3] of Byte;ππ Procedure makekey(Var k; Var s : LongInt);π Var t : LongInt Absolute k;π rec : Recordπ Case Byte ofπ 1 :(b : LongInt; c : Word);π 2 :(d : Word ; e : LongInt);π 3 :(r : Real);π end;π beginπ RandSeed := t;π rec.r := random;π s := s xor rec.b xor rec.e;π end;ππ beginπ temp := 0;π For x := 1 to len-3 do beginπ For y := 0 to 3 doπ tempst[y] := Byte(st[x + y]);π makekey(tempst,temp);π end;π Key := temp;π end;ππFunction EncryptStr(key : LongInt; st : String): String;π Varπ len : Byte Absolute st;π cnt,x : Byte;π temp,CodeStr : String;π beginπ CodeStr := MakeCodeStr(key,st);π temp[0] := st[0];π temp[len] := st[len];π For x := 1 to len-1 do beginπ cnt := ord(st[x]) xor ord(CodeStr[x]);π temp[x] := chr(cnt);π end;π cnt := ord(st[len]) xor len;π temp[len] := chr(cnt);π EncryptStr := temp;π end;ππFunction hashcode(st : String; Var nwd : Word): Word;π Var k : LongInt;π len : Byte Absolute st;π s : String;π beginπ k := key(st) * nwd;π st := StUpCase(st);π s := CompressStr(st);π move(s[1],nwd,2);π if len < 4 then st := st + '!@#$';π {-Force String to a minimum length}π st := EncryptStr(k,st);π st := EncryptStr(Key(st),st);π hashcode := key(st) shr 16;π end; {hash}ππend.πππ{π> Procedure Hash(p : Pointer; numb : Byte; Var result: LongInt);ππ> ... Is this the way that you were referring to storing passWords?π> if so could further explain the usage of this Procedure? Thanx!!ππYes, but I take issue With the Word "store". Storing the passWord hash is notπstoring the passWord as the passWord cannot be determined by examining the hashπ- even if the hash algorithm is known.ππto use the Procedure -ππWhen the passWord is first created, calculate its hash and store that valueπsomewhere - either in a File or in the exe.ππthen when the passWord is used just -ππ Hash(@passWord,length(passWord),EnteredHash);π if PwdHash = EnteredHash then PassWord_Entered_is_Correct.π} 10 05-28-9313:40ALL SWAG SUPPORT TEAM PASCASE.REP IMPORT 13 e├`c CHECKSUM.PASπ Program : 8π Procedure : 1π LongInt : 2π Word : 1π File : 7π For : 3πMade 22 changes to CHECKSUM.PAS in 0.88 seconds.ππCOPYINC.PASπ Program : 6π Uses : 1π Unit : 1π Const : 6π Var : 1π String : 5π LongInt : 2π Word : 1π File : 11π Text : 10π For : 1πMade 45 changes to COPYINC.PAS in 1.04 seconds.ππENCRYPT.PASπMade 0 changes to ENCRYPT.PAS in 1.87 seconds.ππENCRYPT1.PASπ String : 1πMade 1 changes to ENCRYPT1.PAS in 0.71 seconds.ππENCRYPT2.PASπMade 0 changes to ENCRYPT2.PAS in 0.77 seconds.ππENCRYPT3.PASπMade 0 changes to ENCRYPT3.PAS in 0.82 seconds.ππENCRYPT4.PASπMade 0 changes to ENCRYPT4.PAS in 0.88 seconds.ππENDECODE.PASπMade 0 changes to ENDECODE.PAS in 1.15 seconds.ππHASH.PASπMade 0 changes to HASH.PAS in 1.21 seconds.ππPASSWORD.PASπMade 0 changes to PASSWORD.PAS in 0.93 seconds.ππPATCHEXE.PASπMade 0 changes to PATCHEXE.PAS in 0.93 seconds.ππXORCODE.PASπ xor : 2πMade 2 changes to XORCODE.PAS in 0.88 seconds.πππFiles Processed : 12πBytes Processed : 30,724πTotal Scans : 1,908πBytes Scanned : 58,621,392πTotal Changes : 70πTotal Time : 12.31 SecondsπBytes Per Second : 4,762,988π 11 05-28-9313:40ALL SWAG SUPPORT TEAM PASSWORD.PAS IMPORT 20 e├x { JL>Help me guys. I'm learning about reading from a File. I am creating aπ JL>Program that will let you set passWord and test a passWord.ππ JL>Also how do you make the screen print a Character like .... instead of aπ JL>Word. So when you enter in a passWord like in BBS it won't show it?ππ------------------------------------X----------------------------------------π}ππProgram TestPW;ππ{πProgrammer : Chet Kress (FidoNet 1:283/120.4)πBeen Tested? : YES, this has been tested. It works!πoriginal Date : 01/01/93πCurrent Version : v1.0πLanguage : Turbo Pascal v7.0πPurpose : Make a passWord routineπ}ππUses Crt;ππProcedure TestPassWord;ππConstπ DataFile = 'PW.DAT'; {The name of the data File containing the passWord}π {Just have one line in the PW.DAT File, and use that as the passWord}ππVarπ PassWordFile : Text; {The name assigned to the data File}π PassCH : Char; {A Character that the user has entered}π TempPassWord : String; {The temporary passWord from the user}π ThePW : String; {The Real passWord from the data File}ππbegin {TestPassWord}π Assign (PassWordFile, DataFile);π Reset (PassWordFile);π ClrScr;π TempPassWord := '';π Write ('Enter passWord: ');π{π I replaced the Readln With this Repeat..Until loop so you can see theπ "periods" instead of the Characters (like you wanted). This is a simpleπ routine, but it should suffice For what you want it to do. It has someπ error checking and backspacing is available too.π}π Repeatπ PassCH := ReadKey;π if (PassCH = #8) and (Length(TempPassWord) > 0) thenπ beginπ Delete (TempPassWord, Length(TempPassWord), 1);π GotoXY (WhereX-1, WhereY);π Write (' ');π GotoXY (WhereX-1, WhereY);π end;π if (PassCH >= #32) and (PassCH <= #255) thenπ beginπ TempPassWord := TempPassWord + PassCH;π Write ('.');π end;π Until (PassCH = #13);π Writeln;π Readln (PassWordFile, ThePW); { <-- You Forgot to add this line }π if TempPassWord = ThePW thenπ beginπ Writeln ('You have received access.');π Writeln ('Loading Program.');π { Do whatever else you want to here }π endπ elseπ beginπ Writeln ('Wrong PassWord.');π end;π Close (PassWordFile);πend; {TestPassWord}ππbegin {Main}π TestPassWord;πend. {Main}ππ 12 05-28-9313:40ALL SWAG SUPPORT TEAM PATCHEXE.PAS IMPORT 20 e├æá { PD> This looks like something I would like to add to my Programs. Myπ PD> question is, how do you modify the .exe from the Program. I can do theπ PD> encryption but don't know how to store the encrypted passWords in theπ PD> Program's own .exe. Any help would be appreciated.π}ππProcedure PatchExeFile(ItemAddr:Pointer;itemsize:LongInt);πVarπ FiletoPatch : File;π HeaderSize : Word;π seeksize : LongInt;π offset : Word;π LDseg : LongInt;π ch : Char;ππbeginπ assign(FiletoPatch, paramstr(0));π reset(FiletoPatch, 1);π seek(FiletoPatch, 8);π blockread(Filetopatch, headersize, sizeof(headersize));π offset := ofs(itemAddr^);π Ldseg := LongInt(Dseg);π seeksize := 16 * (LDseg - PrefixSeg + HeaderSize) + offset - 256π seek(Filetopatch, seeksize);π blockWrite(Filetopatch, ItemAddr^, ItemSize);π close(Filetopatch);πend;ππ{Call it this way:π}πPatchExeFile(Addr(passWords), sizeof(passWords));ππ{note that For this to work, passWords must be a TypeD ConstANT.πSo you declare it this way:π}π PassWords : PassWord_Array =π (π (PassWord : #247#154#189#209#18#104#143#29; Protected : False),π .π .π .π (PassWord : #247#154#189#209#18#104#143#29; Protected : False)π );ππ{ PassWord_Array is declard as an Array of PassWord_Record;ππ The above declaration is from my Crypto.inC. I have a Crypto.PASπProgram that generates this File from my Make File so that on eachπCompile the encryption is changed and the Array of passWords is storedπwith valid encrypted passWords. I used #<AsciiValue> because theπencryption can generate values from Ascii 0 to Ascii 255 and some ofπthose cause troubles in Strings Constants using "'" as delimeters.ππ As long as you use:ππConst <ConstName> : <ConstType> = <ConstantValue>;ππ You will be sure PatchExe can find it's correct adress in the EXE.πFrom there on you can read it in your TP Program as usual and store itπusing the call to PatchExe I gave up there.ππ BTW, do as I do and generate a new random encryption key on eachπrun, Re-encrypting everything and writting it back to the exe. Thisπdrives Hackers mad when they try to decypher your encrypted passWords.ππOne last note:π The above PatchExe was written when I used TP 6.0. I haven't checkedπ yet if TP 7.0 Uses different mapping of his EXe and it will mostπ probably not work on a Protected-mode Compiled EXE.π}π 13 05-28-9313:40ALL SWAG SUPPORT TEAM SOUNDEX.PAS IMPORT 12 e├t {πREYNIR STEFANSSONππSomebody was saying something about Soundex hashing. Here is myπImplementation of that:π}ππUnit Soundex;ππInterfaceππTypeπ Sdx4 = String[4];ππFunction SoundexOf(WorkStr : String) : Sdx4;ππImplementationππVarπ Group : Array[0..6] of String[8];ππFunction ValidityOf(Letter : Char) : Char;πVarπ Valu, j : Integer;π Chs : String[8];πbeginπ For Valu := 0 to 6 DOπ beginπ Chs := Group[Valu];π For j := 1 to Length(Chs) DOπ beginπ if UpCase(Letter) = Chs[j] thenπ ValidityOf := Chr(48+Valu);π end;π end;πend;ππFunction SoundexOf(WorkStr : String) : Sdx4;πVarπ Sndex : Sdx4;π Oval,π Valu : Char;π i : Integer;πbeginπ Sndex := Copy(WorkStr, 1, 1);π Oval := ValidityOf(WorkStr[1]);π For i := 2 to Length(WorkStr) DOπ beginπ Valu := ValidityOf(WorkStr[i]);π if (Valu <> '0') and (Valu <> Oval) thenπ Sndex := Sndex + Valu;π Oval := Valu;π end;π Sndex := Sndex + '000';π SoundexOf := Sndex;πend;ππbeginπ Group[0] := 'AEHIOUWY';π Group[1] := 'BFPV';π Group[2] := 'CGJKQSXZ';π Group[3] := 'DT';π Group[4] := 'L';π Group[5] := 'MN';π Group[6] := 'R';πend.ππ{πA Soundex-String looks like: `G032', one letter and three numbers.πDonald Knuth wrote about Soundexing in his _Art of Computer Programming_πseries. I got my information out of Personal ComputerWorld (PCW), which inπturn got it from Knuth.π}π 14 05-28-9313:40ALL SWAG SUPPORT TEAM XORCODE.PAS IMPORT 11 e├X4 {π│ Is if possible For you to post a sample code on how to use xor toπ│ encrypt a File??? I'm shifting ORD value around to do excryptionsπ│ and I think your method is better.. So I would like to learn it..ππSure, here's a simple example that reads a user-entered line andπencrypts it using the xor method. By XOR-ing it again the line isπdecrypted. This won't keep NSA fooled For more than a few seconds, butπso long as you keep the passWord hidden it should suffice.π}πππProgram Sample;ππUsesπ Crt;ππConstπ PassWord : Array[1..8] of Char = 'Sha Zamm';ππVarπ PassBits : Array[1..8] of Byte Absolute PassWord;π ALine : String[80];π LineBits : Array[0..80] of Byte Absolute ALine;π I, J, K : Integer;πbeginπ WriteLn('Enter a line of Text to encrypt:');π ReadLn(ALine);π J := 0;π For I := 1 to Length(ALine) Doπ beginπ Inc(J);π If J > 8 Thenπ J := 1;π LineBits[I] := LineBits[I] xor PassBits[J];π end;π WriteLn('Encrypted: ',ALine);π J := 0;π For I := 1 to Length(ALine) Doπ beginπ Inc(J);π If J > 8 Thenπ J := 1;π LineBits[I] := LineBits[I] xor PassBits[J];π end;π WriteLn('Decrypted: ',ALine);πend.π 15 05-31-9308:13ALL SWAG SUPPORT TEAM Encode/Decode w/ PasswordIMPORT 116 e├{` (*-----π Program : CODE/DECODEππ File : Code.Pasππ Version : 1.2ππ Author(s) : Mark Midgleyππ Dateπ (Started) : April 11, 1990π Dateπ (Finished) : , 1990ππ Comment(s) :ππ-----*)πProgram Code_and_DeCode;πππ{$IFDEF DEBUG}π {$D+} (* Turn Debugging Info **ON** *)π {$L+} (* Turn Local Symbols **ON** *)π {$R+} (* Turn Range Checking **ON** *)π {$S+} (* Turn Stack Checking **ON** *)π{$ELSE}π {$D-} (* Turn Debugging Info **OFF** *)π {$L-} (* Turn Local Symbols **OFF** *)π {$R-} (* Turn Range Checking **OFF** *)π {$S-} (* Turn Stack Checking **OFF** *)π{$ENDIF}ππUsesπ Crt,π Dos;ππConstπ BufSize = 512;π Version = '1.3';π MaxError = 7;ππTypeπ EDMode = (EnCrypt,EnCryptPass,DeCrypt);π String79 = String[79];π FilePaths = Array [1..2] Of String79;π Errors = 1..(MaxError - 1);ππProcedure WriteXY( X,Y : Byte; S : String79 );πBegin (* WriteXY *)π GotoXY(X,Y);π Write(S);πEnd; (* WriteXY *)ππFunction UpStr( S : String ) : String;πVarπ X : Byte;ππBegin (* UpStr *)π For X := 1 To Length(S) Doπ S[x] := (UpCase(S[x]) );π UpStr := S;πEnd; (* UpStr *)ππProcedure Center( Y : Byte; S : String; OverWriteMode : Errors );πVarπ X : Byte;ππBegin (* Center *)π GotoXY(1,Y);π Case (OverWriteMode) ofπ 1 : For X := 2 To 78 Do WriteXY(X,WhereY,' ');π 2 : ClrEOL;π End; (* Case *)π X := ((79 - Length(S)) Div 2);π If (X <= 0) Then X := 1;π WriteXY(X,Y,S);πEnd; (* Center *)ππProcedure OutError( S : String79; X,OWM : Errors );πVarπ T : String79;ππBegin (* OutError *)π GotoXY(1, WhereY);π Case ( X ) Ofπ 1 : T := ('Incorrect Number of parameters.');π 2 : T := ('Input file "'+ S +'" not found.');π 3 : T := ('Input and Output files conflict.');π 4 : T := ('User Aborted!');π 5 : T := ('Input file "'+ S +'" is corrupted!');π 6 : If (T = '') Then T := ('DOS Input/Output Failure.')π Else T := S;π End; (* Case *)π TextColor(LightRed);π Center(WhereY,T,OWM);π TextColor(LightGray);π If (OWM = 1) Then WriteLn;π WriteLn;π Halt(x);πEnd; (* OutError *)ππProcedure HelpScreen( FullScreen : Boolean );πBegin (* HelpScreen *)π TextColor(LightGray);π GotoXY(1,WhereY);π WriteLn(' USAGE: CODE [/D|/E|/P] INPUT_FILE OUTPUT_FILE');π WriteLn(' Options are: /D Decode File.');π WriteLn(' /E Encode File.');π WriteLn(' /P Encode with Password.');π If (Not FullScreen) Then Halt(MaxError);π WriteLn;π WriteLn('Description:');π WriteLn;π WriteLn(' CODE encrypts a DOS file to garbage using a randomly generated seed');π WriteLn(' and then back again. For more protection, the password option can be used.');π WriteLn(' Note: With no option, CODE defaults to encode "/E"; Input and Output files');π WriteLn(' must be different; the "/P" option will prompt for the password and echo');π WriteLn(' dots; Code does not allow wildcards; Pressing ESCape during operation will');π WriteLn(' abort. The author does not guarantee the reliability of this program and');π WriteLn(' is not responsible for any data lost. If you appreciate this program in any');π WriteLn(' way or value its use then please send $5.00 - $20.00 to:');π WriteLn;π TextColor(White);π WriteLn(' Mark "Zing" Midgley');π WriteLn(' 843 East 300 South');π WriteLn(' Bountiful Ut, 84010');π TextColor(LightGray);π Halt(MaxError);πEnd; (* HelpScreen *)ππFunction Shrink( P : PathStr ) : String79;πVarπ D : DirStr;π N : NameStr;π E : ExtStr;ππBegin (* Shrink *)π FSplit(P,D,N,E);π Shrink := N + E;πEnd; (* Shrink *)ππProcedure GraphIt( Var F1, F2 : File;π Var OldX : Byte;π Hour,π Min,π Sec,π Sec100 : Word;π BoxSetUp : Boolean );πVarπ F1Size,π F2Size : LongInt;π Percent,π X,π NewX : Byte;π H,π M,π S,π S100 : Word;π A,π B,π C,π D,π Temp : String79;ππBegin (* GraphIt *)π If (BoxSetUp) Thenπ Beginπ Percent := 0;π OldX := 3;π GotoXY(1,WhereY);π WriteLn('╔═════════════════════════════════════════════════════════════════════════════╗');π WriteLn('║ ║');π WriteLn('╚═════════════════════════════════════════════════════════════════════════════╝');π GotoXY(3,WhereY - 2);π End Elseπ Beginπ GetTime(H,M,S,S100);π If (Sec100 <= S100) Then Dec(S100,Sec100)π Elseπ Beginπ S100 := (S100 + 100 - Sec100);π If (S > 0) Then Dec(S);π End;π If (Sec <= S) Then Dec(S,Sec)π Elseπ Beginπ S := (S + 60 - Sec);π If (M > 0) Then Dec(M);π End;π If (Min <= M) Then Dec(M,Min)π Elseπ Beginπ M := (M + 60 - Min);π If (H > 0) Then Dec(H);π End;π If (Hour <= H) Then Dec(H,Hour)π Else H := (H + 12 - Hour);π Str(H,A);π Str(M,B);π Str(S,C);π Str(S100,D);π Case (S100) ofπ 0..9 : D := ('0' + D);π End; (* Case *)π If (M > 0) Thenπ Case (S) ofπ 0..9 : C := ('0' + C);π End; (* Case *)π If (H > 0) Thenπ Case (M) ofπ 0..9 : B := ('0' + B);π End; (* Case *)π If (H = 0) Thenπ Beginπ If (M = 0) Then Temp := (Concat(C,'.',D,' sec') )π Else Temp := (Concat(B,' min ',C,'.',D,' sec') );π Endπ Else If (H = 1) Then Temp := (Concat(A,' hr ',B,' min ',C,'.',D,' sec') )π Else Temp := (Concat(A,' hrs ',B,' min ',C,'.',D,' sec') );π F1Size := FileSize(F1);π F2Size := FileSize(F2);π If (F2Size <= F1Size) Thenπ Percent := ((F2Size * 100) Div F1Size )π Else Percent := 100;π NewX := (((Percent * 76) Div 100) + 2);π If (NewX < 3) Then NewX := 3;π For X := OldX To NewX Do WriteXY(X,WhereY,#176);π OldX := NewX;π Center(WhereY + 1,(#181 + ' ' + Temp + ' ' + #198),3);π GotoXY(NewX,WhereY - 1);π End;πEnd; (* GraphIt *)ππProcedure Rm( FileName : String79 );πVarπ F : File;ππBegin (* Rm *)π If (FileName = '') Then Exit;π Assign(F,FileName);π Erase(F);πEnd; (* Rm *)ππProcedure GetStr( Var S : String79; Prompt,FName : String79; Show : Boolean );πVarπ Max,π Min : Byte;π A : Char;π X : Byte;ππBegin (* GetStr *)π If (FName = '') Thenπ Beginπ Max := 54;π Min := 0π End Elseπ Beginπ Max := 25;π Min := 3π End;π TextColor(LightGray);π WriteXY(1,WhereY,Prompt);π Repeatπ GotoXY(Length(Prompt) + 1,WhereY);π ClrEOL;π If (Show) Then WriteXY(Length(Prompt) + 1,WhereY,S)π Else For X := 1 To Length(S) Do Write(#249);π A := (ReadKey);π Case ( A ) ofπ #32..#126 :π If (Length(S) < Max) Then S := S + Aπ Elseπ Beginπ Sound(100);π Delay(12);π NoSound;π End;π #8 :π If (Length(S) > 0) Thenπ Delete(S,(Length(S) ), 1);π #0 :π A := ReadKey;π #27:π Beginπ Rm(FName);π OutError('',4,2);π End;π End; (* Case *)π Until (A = #13) And (Length(S) >= Min);πEnd; (* GetStr *)ππFunction RealFile( St : String79; OWM : Errors ) : Boolean;πVarπ Error : Word;π F : File;ππBegin (* RealFile *)π RealFile := False;π Assign(F,St);π {$I-} (* Turn Input/Output-Checking Switch Off *)π Reset(F); (* Open file. *)π Error := IOResult;π {$I+} (* Turn Input/Output-Checking Switch On *)π If (Error = 0) Then (* File exists. *)π Beginπ RealFile := True;π Close(F);π End Elseπ{*} Case (Error) Ofπ 152 : OutError('Drive Not Ready.',6,OWM);π 3 : OutError('Invalid Drive specification.',6,OWM);π (* 5 : Directory *)π End; (* Case *)πEnd; (* RealFile *)ππProcedure CheckError( FileName, Msg : String79 );πVarπ Error : Word;ππBegin (* CheckError *)π Error := IOResult;π If (Error <> 0) Thenπ Beginπ If (Error <> 152) Andπ (Error <> 3) Then Rm(FileName)π Else Msg := ('Drive Not Ready.');π OutError(Msg,6,1);π End;πEnd; (* CheckError *)ππProcedure CheckAbort( FileName : String79 );πBegin (* CheckAbort *)π If (KeyPressed) Thenπ If (ReadKey = #27) Thenπ Beginπ Rm(FileName);π OutError('',4,1);π End;πEnd; (* CheckAbort *)ππ(*----π Procedure Encode();ππ Author(s) : Mark Midgleyπ Louis Zirkelππ Comments : Cool Man...ππ----*)ππProcedure EnCode( _File : FilePaths; Protect : Boolean );πVarπ Seed,π PI,π Y,π OldX : Byte;π I,π Increment : Integer;π Buf : Array [1..BufSize] of Char;π Hour,π Min,π Sec,π Sec100,π Status : Word;π Temp,π Pass : String79;π F1,π F2 : File;ππBegin (* EnCode *)π Pass := '';π {$I-}π Assign(F1, _File[1]); (* input file *)π Assign(F2, _File[2]); (* output file *)π Reset(F1,1);π CheckError('','Couldn''t open input file.');π ReWrite(F2,1);π CheckError(_File[2],'Couldn''t create output file.');π Randomize;π If (Protect) Thenπ Beginπ GetStr(Pass,'(3 Char min, 25 Char max) Enter Password: ',_File[2],False);π Buf[1] := Chr(Random(127) );π BlockWrite(F2,Buf[1],SizeOf(Buf[1]),Status);π CheckError(_File[2],'Couldn''t write to output file.');π End Elseπ Beginπ Buf[1] := Chr(Random(127) + 127);π BlockWrite(F2,Buf[1],SizeOf(Buf[1]),Status);π CheckError(_File[2],'Couldn''t write to output file.');π End;π Seed := Ord(Buf[1]);π Increment := 1;π PI := 1;π Y := 127;π TextColor(LightGray);π ClrEOL;π GetTime(Hour,Min,Sec,Sec100);π GraphIt(F1,F2,OldX,Hour,Min,Sec,Sec100,True);π Repeatπ BlockRead(F1, Buf, BufSize, Status);π CheckError(_File[2],'Couldn''t read input file.');π CheckAbort(_File[2]);π GraphIt(F1,F2,OldX,Hour,Min,Sec,Sec100,False);π For I := 1 To BufSize Doπ Beginπ If (Protect) Thenπ Beginπ Buf[I] := Char(Byte(Buf[I]) XOR Byte(Pass[PI]));π If (PI = Length(Pass)) Then Increment := -1;π If (PI = 1) Then Increment := 1;π Inc(PI,Increment);π Endπ Elseπ Beginπ Buf[I] := Char(Byte(Buf[I]) XOR Y);π End;π End;π BlockWrite(F2, Buf, Status);π CheckError(_File[2],'Couldn''t write to output file.');π Until (Status < BufSize);π Close(F1);π CheckError(_File[2],'Couldn''t close input file.');π Close(F2);π CheckError(_File[2],'Couldn''t close output file.');π {$I+}π(* Successful Encryption *)π TextColor(LightGray);π Temp := (Shrink(_File[1]) +' Encoded to '+ Shrink(_File[2]));π If (Protect) Then Temp := (Temp + ' with Password.');π Center(WhereY,Temp,1);π GotoXY(1,WhereY + 1);π WriteLn;πEnd; (* EnCode *)ππ(*----π Procedure DeCode();ππ Author(s) : Mark Midgleyπ Louis Zirkelππ Comments : Cool Man...ππ----*)ππProcedure DeCode( _File : FilePaths );πVarπ Seed,π PI,π Y,π OldX : Byte;π I,π Increment : Integer;π Buf : Array [1..BufSize] of Char;π Hour,π Min,π Sec,π Sec100,π Status : Word;π Temp,π Pass : String79;π F1,π F2 : File;ππBegin (* DeCode *)π Pass := '';π {$I-}π Assign(F1, _File[1]);π Assign(F2, _File[2]);π Reset(F1,1);π CheckError('','Couldn''t open input file.');π ReWrite(F2,1);π CheckError(_File[2],'Couldn''t create output file.');π BlockRead(F1,Buf[1],SizeOf(Buf[1]),Status);π CheckError(_File[2],'Couldn''t read input file.');π Seed := Ord(Buf[1]);π If (Buf[1] < #127) Then (* There's a Password *)π GetStr(Pass,'Enter Password: ',_File[2],False);π Increment := 1;π PI := 1;π Y := 127;π TextColor(LightGray);π ClrEOL;π GetTime(Hour,Min,Sec,Sec100);π GraphIt(F1,F2,OldX,Hour,Min,Sec,Sec100,True);π Repeatπ BlockRead(F1, Buf, BufSize, Status);π CheckError(_File[2],'Couldn''t read input file.');π GraphIt(F1,F2,OldX,Hour,Min,Sec,Sec100,False);π CheckAbort(_File[2]);π For I := 1 To BufSize Doπ Beginπ If (Pass <> '') Then (* There's a Password *)π Beginπ Buf[I] := Char(Byte(Buf[I]) XOR Byte(Pass[PI]));π If (PI = Length(Pass)) Then Increment := -1;π If (PI = 1) Then Increment := 1;π Inc(PI,Increment);π Endπ Elseπ Beginπ Buf[I] := Char(Byte(Buf[I]) XOR Y);π End;π End;π BlockWrite(F2, Buf, Status);π CheckError(_File[2],'Couldn''t write to output file.');π Until (Status < BufSize);π Close(F1);π CheckError(_File[2],'Couldn''t close input file.');π Close(F2);π CheckError(_File[2],'Couldn''t close output file.');π {$I+}π(* Successful Decryption *)π Center(WhereY,Shrink(_File[1]) +' Decoded to '+ Shrink(_File[2]),1);π GotoXY(1,WhereY + 1);π WriteLn;πEnd; (* DeCode *)ππProcedure CheckParameters;πVarπ _File : FilePaths;π Temp : String79;π Mode : EDMode;π OkMode,π Input1,π Input2 : Boolean;π X : Byte;ππBegin (* CheckParameters *)π For X := 1 To 2 Do _File[x] := '';π Mode := EnCrypt;π OkMode := False;π X := 1;π While (X <= ParamCount) Doπ Beginπ Temp := (UpStr(ParamStr(x) ) );π If (Pos('?',Temp) > 0) or (Pos('*',Temp) > 0) Then HelpScreen(True);π If ((Temp[1] = '/') or (Temp[1] = '-')) Andπ (Length(Temp) = 2) And (Not OkMode) Thenπ Beginπ Case (Temp[2]) ofπ 'E' : Beginπ Mode := EnCrypt;π OkMode := True;π End;π 'D' : Beginπ Mode := DeCrypt;π OkMode := True;π End;π 'P' : Beginπ Mode := EnCryptPass;π OkMode := True;π End;π 'H',π '?' : HelpScreen(True);π Elseπ OkMode := False;π End; (* Case *)π End Elseπ Beginπ If (_File[1] = '') Then _File[1] := Temp Elseπ If (_File[2] = '') Then _File[2] := Temp;π End;π Inc(x);π End;π If (_File[1] = '') Thenπ Beginπ GetStr(_File[1],'Enter Input Path/File : ','',True);π Input1 := True;π _File[1] := (UpStr(_File[1]) );π End Else Input1 := False;π If (_File[2] = '') Thenπ Beginπ GetStr(_File[2],'Enter Output Path/File : ','',True);π Input2 := True;π _File[2] := (UpStr(_File[2]) );π End Else Input2 := False;π If (Pos('?',_File[1]+_File[2]) > 0) or (Pos('*',_File[1]+_File[2]) > 0)π Then HelpScreen(True);π If (Not OkMode) And ((Input1) or (Input2)) Andπ (_File[1] <> '') And (_File[2] <> '') Thenπ Beginπ WriteXY(1,WhereY,'[E]ncode, Encode with [P]assword, or [D]ecode? ');π ClrEOL;π Case (UpCase(ReadKey) ) ofπ 'E' : Mode := EnCrypt;π 'D' : Mode := DeCrypt;π 'P' : Mode := EnCryptPass;π #27 : OutError('',4,2);π End; (* Case *)π End Else If (_File[1] = '') or (_File[2] = '') Then HelpScreen(False);π If ((ParamCount < 2) or (ParamCount > 3)) Andπ (_File[1] = '') And (_File[2] = '') Then OutError('',1,2);π If (Not(RealFile(_File[1],2) ) ) Then OutError(Shrink(_File[1]),2,2);π If (RealFile(_File[2],2) ) Thenπ Beginπ If (FExpand(_File[1]) = FExpand(_File[2]) ) Then OutError('',3,2);π TextColor(Red);π WriteXY(1,WhereY,'Warning! "');π TextColor(LightRed);π Write(Shrink(_File[2]) );π TextColor(Red);π Write('" already exists...Replace ([Y],N)? ');π ClrEOL;π Case (UpCase(ReadKey) ) Ofπ 'N',#27 : OutError('',4,2);π End; (* Case *)π End;π If (Mode = EnCryptPass) Then EnCode(_File,True);π If (Mode = EnCrypt) Then EnCode(_File,False);π If (Mode = DeCrypt) Then DeCode(_File);πEnd; (* CheckParameters *)ππProcedure Main;πBegin (* Main *)π CheckBreak := False;π TextColor(LightGray);π WriteLn;π ClrEOL;π WriteXY(12,WhereY,'DOS file Encrypter v' + Version + ' by ');π TextColor(LightBlue);π Write('Zing Merway');π TextColor(LightGray);π WriteLn(' CODE/h for Help.');π WriteLn;π CheckParameters;πEnd; (* Main *)ππBegin (* Code *)π Main;πEnd. (* Code *) 16 08-27-9320:53ALL KEITH TYSINGER An Encoder for passwords IMPORT 16 e├Γ {πKEITH TYSINGERππYou can make an encoder that will scramble a string(s) that even YOU, theπ programmer couldn't unscramble without a password. They are many differentπ ways to scramble a string; just be creative! One way is to swap everyπ character with another character ( ex. swap every letter 'A' with the numberπ '1') , a better way would use a password to scramble it. Here is a simpleπ procedure that requires the password, the string to be scrammbled, and returnsπ the scrambled string. The password should not exceed 20 characters in length.πForget about the messy code; I blame my word processor:π}ππprocedure encode(password, instring : string; var outstring : string);πvarπ len,π pcounter,π scounter : byte;ππbeginπ len := length(password) div 2;π scounter := 1;π pcounter := 1;ππ repeatπ outstring := outstring + chr(ord(password[pcounter]) +π ord(instring[scounter]) + len);π inc(scounter);π inc(pcounter);π if pcounter > length(password) thenπ pcounter := 1;π until scounter > length(instring);πend;ππprocedure decode(password, instring : string; var outstring : string);πvarπ len,π pcounter,π scounter : byte;ππbeginπ len := length(password) div 2;π scounter := 1;π pcounter := 1;ππ repeatπ outstring := outstring + chr(ord(instring[scounter]) -π ord(password[pcounter]) - len);π inc(scounter);π inc(pcounter);π if pcounter > length(password) thenπ pcounter := 1;π until scounter > length(instring);πend;ππvarπ password,π original,π scrambled,π descrambled : string;πbeginπ original := 'Hello There!';π password := 'Eat my';π encode(password, original, scrambled);π writeln('orig = ', original);π writeln('scrm = ', scrambled);π decode(password, scrambled, descrambled);π writeln('dcod = ', descrambled);π readln;πend.ππ 17 08-27-9321:35ALL SWAG SUPPORT TEAM RSA Encryption IMPORT 11 e├l| RSA encryption.ππ The encryption key is: C = M to the power of e MOD nππ where C is the encrypted byte(s)π M is the byte(s) to be encryptedπ n is the product of p and qπ p is a prime number ( theoretically 100 digits long )π q is a prime number ( theoretically 100 digits long )π e is a number that gcd(e,(p-1),(q-1)) = 1ππ The decryption key is: M = C to the power of d MOD nππ Where C is the encrypted byte(s)π M is the original byte(s)π n is the product of p and qπ p is a prime number ( must be the same as the encrypting one )π q is a prime number ( " " " " )π d is the inverse of the modulo e MOD (p-1)(q-1)πππAs you can see in order to crack the encrypted byte(s) you would need to knowπthe original prime #'s, Even with the encryption key it would take a long timeπto genetate the correct prime #'s needed....ππan Example...ππ C = M to the power of 13 MOD 2537ππ 2537 is the product of 43 and 59.ππ the decryption key isππ M = C to the power of 937 MOD 2537ππ 937 is the inverse of 13 MOD (43 - 1)(59 - 1).ππ 18 05-25-9408:18ALL JOHN FREESE Xor Encryption/DecryptionSWAG9405 96 e├ (* $Header: A:/vcs/mash.pav 1.0 15 Jul 1991 7:21:38 K_McCoy $ *)π(****************************************************************************)π πUNIT MASH;π π{$IFDEF DOCUMENTATION}π π(****************************************************************************)π * π * $Log: A:/vcs/mash.pav $π * π * Rev 1.0 15 Jul 1991 7:21:38 K_McCoyπ * Added encryption unit, cleaned up.π * π * π(****************************************************************************)π π{$V-}π π π Mash - The McCoy & Associates File Manglerπ π Purpose:πππ General purpose text file encrypter. Keeps the honest people honest.π Does simple XOR of text characters with user settable key. Createsπ a binary file with the extension .CRP containing the encrypted text.π Binary files will be a little shorter than their ascii counterpartsπ as there will be no CR/LF delimiters: only a length byte preceedingπ each "line" of binary characters. There is a 255 character limit onπ the text files, but no limit on the number of lines (up to the capacityπ of the disk).π π Drawbacks: This is nowhere near as secure as DES algorithm, althoughπ it is much faster. This unit won't keep the CIA / KGB out of yourπ financial records for long, but it might work on your ex-wifeπ and her laywer.π π Note: This unit uses the TPSTRING unit from Turbo Power. You couldπ easily change this to use the OPSTRING unit or write your ownπ Trim [trailing blanks] function.π π I wrote this for an automated test program to keep unauthorized peopleπ from changing the test specifications out on the assembly line.π (You wouldn't want airplanes falling on your head, would you?)π π Suggested improvements:ππ Allow other file extensions for input and output files.π Modify this to work with binary input files.π Modify the Mangle routine to not reset to the beginning of the key on eachπ line of text.π π Public Domain, but be nice and give me credit if you use it in yourπ own stuff.π π _Use at your own risk_ If the KGB de-encrypts your Mangled bowlingπ scores, tough!ππ Do an IO redirect of complaints to NUL. Questions may be sent to:π π Kevin McCoy - CompuServe ID# [72470,1233]π 2217 Aspenpark Ct.π Thousand Oaks, CA 91362-1731π π π Sample Usage:πUSESπ DOS,π CRT,π MASH;πVARπ Strg,π InName : STRING;π M : Mangler;πBEGIN {main}π ClrScr;π π WRITE('Enter name of .CFG file: ');π READLN(InName);π π {I think this came from an old "Man from U.N.C.L.E." episode}π M.SetSequence('OuR CaRs On IcE');ππ {open the two files}π IF NOT M.Init(InName, MASHMODE) THEN BEGINπ WRITELN(M.MashError);π HALT(1);π END;π π {encrypt the .CFG file}π IF NOT M.MashFile THEN BEGINπ WRITELN(M.MashError);π HALT(1);π END;ππ {close the files}π M.Done;π π {Open just the encrypted file}π IF NOT M.Init(InName, UNMASHMODE) THEN BEGINπ WRITELN(M.MashError);π HALT(1);π END;π π {read and decrypt each line until EOF}π WHILE M.Getline(Strg) DOπ WRITELN(Strg);π π {close the .CRP file}π M.Done;π πEND; {of sample program}π π π{$ENDIF}π{ The real stuff starts here... }π πINTERFACEππTYPEπ MMType = (MASHMODE, UNMASHMODE, SOURMASH);π π Mangler = OBJECTπ TFile : TEXT;π BFile : FILE;π LastError : WORD;π FileName : STRING;π InitMode : MMType;π FUNCTION Init(Fname : STRING; Mode : MMType) :πBOOLEAN;π FUNCTION Getline(VAR Line : STRING) : BOOLEAN;π FUNCTION MashFile : BOOLEAN;π FUNCTION MashError(VAR S : STRING) : BOOLEAN;π PROCEDURE SetSequence(Seq : STRING);π PROCEDURE Done;π END;π π π(****************************************************************************)π πIMPLEMENTATIONππUSESπ {.U-}π TPSTRINGπ {.U+}π ;π πCONSTπ {Default key. May be reset with the SetSequence method}π Id : STRING =π'^%12hY7eujEDZ|R9a341~~#2DBC3fn7mSDVvUY@hbFD`6093fdk79*7a-|- Q`';π π {error number constants}π INVINAM = 500;π INVINIT = INVINAM + 1;π CORRUPT = INVINIT + 1;π π π π(****************************************************************************)π π FUNCTION Mangle(L : STRING) : STRING;π { Low budget encryption / decryption of Line}π VARπ I : INTEGER;π BEGINπ FOR I := 1 TO LENGTH(L) DOπ L[I] := CHR(ORD(L[I]) XOR NOT(ORD(Id[I MOD LENGTH(Id) + 1])));π Mangle := L;π END;π π π(****************************************************************************)π π FUNCTION Mangler.Init(Fname : STRING; Mode : MMType) : BOOLEAN;π {- Gozintas: Fname = Name (no extension) of the input/output files}π { Mode = MASHMODE / UNMASHMODE (encrypt / decrypt) }π { Gozoutas: TRUE if everything was OK, FALSE if not }π VARπ InName,π OutName : STRING;π BEGINπ InitMode := Mode;π FileName := Fname;π Init := TRUE;π IF LENGTH(Trim(Fname)) = 0 THEN BEGINπ LastError := INVINAM;π Init := FALSE;π EXIT;π END;π InName := Fname + '.CFG';π OutName := Fname + '.CRP';π π { Open the appropriate file(s) }π π IF Mode = MASHMODE THEN BEGINπ ASSIGN(TFile, InName); {open data files}π {$I-}π RESET(TFile);π {$I+}π LastError := IORESULT;π IF LastError <> 0 THEN BEGINπ {crash if file error}π Init := FALSE;π EXIT;π END;π ASSIGN(BFile, OutName);π {$I-}π REWRITE(BFile, 1);π {$I+}π LastError := IORESULT;π IF LastError <> 0 THEN BEGINπ {crash if file error}π Init := FALSE;π EXIT;π END;π Init := TRUE;π ENDπ ELSE BEGINπ ASSIGN(BFile, OutName); {open data files}π {$I-}π RESET(BFile, 1);π {$I+}π LastError := IORESULT;π IF LastError <> 0 THEN BEGINπ {crash if file error}π Init := FALSE;π EXIT;π END;π END;π END;π π π(****************************************************************************)π π FUNCTION Mangler.Getline(VAR Line : STRING) : BOOLEAN;π {- Read a single line of binary gunk from the MSH file and decrypt it}π { Gozintas = Nothing }π { Gozoutas: Line = Decrypted ASCII string }π { Returns TRUE if everything was OK, FALSE if not }π VARπ Result : WORD;π BEGINπ π Line := '';π Getline := FALSE;π π IF InitMode <> UNMASHMODE THEN BEGINπ LastError := INVINIT;π EXIT;π END;π π BLOCKREAD(BFile, Line[0], 1, Result);π IF Result <> 1 THEN BEGINπ LastError := CORRUPT;π EXIT;π END;π π BLOCKREAD(BFile, Line[1], ORD(Line[0]), Result);π IF Result = ORD(Line[0]) THEN BEGINπ Line := Mangle(Line);π Getline := TRUE;π ENDπ END;π π π(****************************************************************************)π π FUNCTION WTOA(N : WORD; W : INTEGER) : STRING;π VARπ Strg : STRING;π BEGINπ STR(N:W, Strg);π WTOA := Strg;π END;π π π(******************************************************************************)π π FUNCTION Mangler.MashError(VAR S : STRING) : BOOLEAN;π {- return the last error string }π BEGINπ {most of these messages are unlikely to occur. You may remove most }π {of them to save memory }ππ MashError := TRUE;π CASE LastError OFπ 000 : BEGIN {no error}π S := '';π MashError := FALSE; π END;π 002 : S := 'File not found';π 003 : S := 'Path not found';π 004 : S := 'Too many open files';π 005 : S := 'File access denied';π 006 : S := 'Invalid file handle';π 012 : S := 'Invalid file access code';π 015 : S := 'Invalid drive number';π 016 : S := 'Cannot remove current directory';π 017 : S := 'Cannot rename across drives';π 100 : S := 'Disk read error';π 101 : S := 'Disk write error';π 102 : S := 'File not assigned';π 103 : S := 'File not open';π 104 : S := 'File not open for input';π 105 : S := 'File not open for output';π 150 : S := 'Disk is write-protected';π 151 : S := 'Unknown unit';π 152 : S := 'Drive not ready';π 154 : S := 'CRC error in data';π 156 : S := 'Disk seek error';π 157 : S := 'Unknown media type';π 158 : S := 'Sector not found';π 160 : S := 'Device write fault';π 161 : S := 'Device read fault';π 162 : S := 'Hardware failure';π 203 : S := 'Insufficient memory';π INVINAM :S := 'Invalid filename';π INVINIT :S := 'Invalid Mash unit init';π CORRUPT : S := 'Invalid or corrupt MSH file';π ELSEπ S := 'Turbo runtime error ' + WTOA(LastError, 4);π END;π END;π π π(****************************************************************************)π π PROCEDURE Mangler.SetSequence(Seq : STRING);π {- Set the encryption sequence (key) to be something other than theπdefault }π { Gozintas: A string (the longer the better) containing any charactersπin }π { the range of (0-255) Try to avoid using strings that will beπduplicated }π { in the text to be encrypted. A match between the key and the textπresults }π { in strings of $FF characters in the MSH file that make the keyπeasier to }π { crack by determined hackers π }π π BEGINπ Id := Seq;π END;ππ π(****************************************************************************)π π FUNCTION Mangler.MashFile : BOOLEAN;π {- File conversion method. Encrypts text file specified in Init methodπcall }π { and places encrypted binary junk into the .MSH file π }π { Returns TRUE if success, FALSE if not π }π VARπ Strg : STRING;π Result : WORD;π BEGINπ WHILE (NOT EOF(TFile)) DO BEGINπ READLN(TFile, Strg);π WRITELN(Strg);π Strg := Mangle(Strg);π BLOCKWRITE(BFile, Strg, ORD(Strg[0]) + 1, Result);π IF Result <> LENGTH(Strg) + 1 THEN BEGINπ WRITELN('Problem writing ' + FileName + '.MSH');π HALT(1);π END;π END; {while}π π END;π π π(****************************************************************************)π π PROCEDURE Mangler.Done;π {- Close up shop and boogie method}π BEGINπ CLOSE(BFile);π IF InitMode = MASHMODE THENπ CLOSE(TFile);π π InitMode := SOURMASH;π END;π π π(****************************************************************************)π {unit initialization}πEND. {of unit mash}π(****************************************************************************)π(****************************************************************************)π