print " - DARKFISH STRONG ENCRYPTION DLL (Example) -" print "Military strength encryption made easy for Dark Basic Pro products!" print " Use at your own risk! May be illegal in some countires!" print "It's free but if you wish to make a donation visit www.KumKie.com/darkfish" print "" print "" ```````````````````````````````````````````````````````````````````````` ` SETTING THE ENCRYPTION PASSWORD FOR GENERATING HASH KEYS ```````````````````````````````````````````````````````````````````````` input "Enter a new password to encrypt with:(default = K1iNg0n!) ",userIn$ if userIn$ = "" userIn$ = "K1iNg0n!" endif start = timer() SetEncryptPassword(userIn$) print "Time taken to generate hash key = " + str$(timer()-start) +"ms" print "" ```````````````````````````````````````````````````````````````````````` ` EXAMPLE OF HOW TO ENCRYPT AND DECRYPT BINARY BYTES ```````````````````````````````````````````````````````````````````````` print "Press a key to encrypt some binary bytes" print "" wait key start = timer() encrypted$ = EncryptBinaryByte("11110000") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptBinaryByte(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptBinaryByte("11001100") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptBinaryByte(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptBinaryByte("10101010") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptBinaryByte(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptBinaryByte("00000000") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptBinaryByte(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" print "" ```````````````````````````````````````````````````````````````````````` ` EXAMPLE OF HOW TO ENCRYPT AND DECRYPT CHARACTER PAIRS ```````````````````````````````````````````````````````````````````````` print "Press a key to encrypt some character pairs" wait key print "" start = timer() encrypted$ = EncryptChars("H","X") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptChars(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptChars("i","e") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptChars(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptChars("(",")") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptChars(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptChars("2","0") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptChars(encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" print "" ```````````````````````````````````````````````````````````````````````` ` EXAMPLE OF HOW TO ENCRYPT AND DECRYPT STRINGS ```````````````````````````````````````````````````````````````````````` print "Press a key to encrypt some strings" wait key print "" start = timer() encrypted$ = EncryptString ("Lower: abcdefghijklmnopqrstuvwxyz") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptString (encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptString ("Numeric: 1234567890") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptString (encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptString ("Upper: ABCDEFGHIJKLMNOPQRSTUVWXYZ") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptString (encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" start = timer() encrypted$ = EncryptString ("Special: {}[] '#@~:;?/<>,.-+_=()*&^%$ £!`¬|\") print str$(timer()-start) +"ms " + encrypted$ start = timer() decrypted$ = DecryptString (encrypted$) print str$(timer()-start) +"ms " + decrypted$ print "" print "" ```````````````````````````````````````````````````````````````````````` ` EXAMPLE OF HOW TO ENCRYPT AND DECRYPT TEXT FILES ```````````````````````````````````````````````````````````````````````` print "Press a key to encrypt a file." wait key input "Enter a text file (default = make reddwarf.txt)",textFile$ print "" if textFile$ = "" textFile$ = "reddwarf.txt" if file exist("reddwarf.txt") then delete file "reddwarf.txt" open to write 1,"reddwarf.txt" write string 1,"Convict: No weapons?" write string 1,"Lister: No weapons. [they advance on the gangway]" write string 1,"Convict: (pulling out a knife) I lied." write string 1,"Lister: So did I. (Smiles as he whips out a steel pipe)" write string 1,"Convict: (pulls out a gun) I lied twice." write string 1,"Lister: (getting worried) I hadn't thought of that..." write string 1," Red Dwarf - BBC" close file 1 endif start = timer() EncryptTextFile(textFile$,"encrypted.txt") stop = timer() open to read 1,"encrypted.txt" while file end(1)=0 read string 1,readString$ print readString$ endwhile close file 1 print textFile$ + " -> encrypt -> encrypted.txt " + str$(stop-start) +"ms " print "" start = timer() DecryptTextFile("encrypted.txt","decrypted.txt") stop = timer() open to read 1,"decrypted.txt" while file end(1)=0 read string 1,readString$ print readString$ endwhile close file 1 print "encrypted.txt -> decrypt -> decrypted.txt " + str$(stop-start) +"ms " print "" ```````````````````````````````````````````````````````````````````````` ` INSTRUCTION ON HOW TO TALK DIRECTLY TO THE DLL TO WRITE YOUR OWN! ```````````````````````````````````````````````````````````````````````` print "Press a key to learn more.." wait key print "" print "" print "You can write you own encryption functions using the DLL interface directly!" print "" print "The interface functions are:" print "DF_SetPass (string$)" print "DF_EncryptDirectSet (dword,dword)" print "dword DF_EncryptDirectGetL()" print "dword DF_EncryptDirectGetR()" print "DF_DecryptDirectSet (dword,dword)" print "dword DF_DecryptDirectGetL()" print "dword DF_DecryptDirectGetR()" print "" print "" print "Have fun, and don't blame me if you forget your password!" print " - GatorHex 2007 (www.KumKie.com)" wait key end ```````````````````````````````````````````````````````````````````````````````````` ` BELOW THIS POINT ARE ALL THE FUNCTION YOU NEED TO COPY INTO YOUR OWN PROJECT ` OR INCLUDE FILE. YOU ALSO NEED TO COPY THE DARKFISH.DLL INTO YOUR DARK BASIC PRO/ ` COMPILER/PLUGINS-USER/ FOLDER. GET IT FROM WWW.KUMKIE.COM/DARKFISH ```````````````````````````````````````````````````````````````````````````````````` `````````````````````````````````````````````````````````````````````````````````` `THIS FUNCTION SETS THE PASSWORD USED TO GENERATE THE HASH KEYS `````````````````````````````````````````````````````````````````````````````````` FUNCTION SetEncryptPassword(hashKey$) DF_SetPass (hashKey$) ENDFUNCTION `````````````````````````````````````````````````````````````````````````````````` `THIS FUNCTION READS A TEXT FILE AND WRITES AN ENCRYPTED FILE `````````````````````````````````````````````````````````````````````````````````` FUNCTION EncryptTextFile(fromFilename$,toFilename$) if file exist(toFilename$) delete file toFilename$ endif open to read 1,fromFilename$ open to write 2,toFilename$ while file end(1)=0 read string 1,readString$ writeString$ = EncryptString(readString$) write string 2,writeString$ endwhile close file 2 close file 1 ENDFUNCTION `````````````````````````````````````````````````````````````````````````````````` `THIS FUNCTION READS AN ENCRYPTED FILE AND WRITES A DECRYPTED FILE ````````````````````````````````````````````````````````````````````````````````` FUNCTION DecryptTextFile(fromFilename$,toFilename$) if file exist(toFilename$) delete file toFilename$ endif open to read 1,fromFilename$ open to write 2,toFilename$ while file end(1)=0 read string 1,readString$ writeString$ = DecryptString(readString$) write string 2,writeString$ endwhile close file 2 close file 1 ENDFUNCTION ``````````````````````````````````````````````````````````````````````````````` ` THIS FUNCTION WILL ENCRYPT A BINARY BYTE (8 bits) PASSED AS A STRING ` THE ENCRYPTION IS WEAKER ON SMALL DATA SO I INTRODUCE A RANDOM NUMBER ` TO MAKE IT LESS PREDICATABLE. WORTH NOTING 1 BYTE BECOMES 2 DWORDS WHICH ` WILL MAKE THE DATA 8x LONGER. ``````````````````````````````````````````````````````````````````````````````` FUNCTION EncryptBinaryByte(byte$) randL$ = STR$(rnd(98)+1) randR$ = STR$(rnd(98)+1) byteL$ = randL$ + left$(byte$,4) byteR$ = randR$ + right$(byte$,4) L as DWORD L = val(byteL$) R as DWORD R = val(byteR$) if DF_EncryptDirectSet (L,R) lEncrypt as dword lEncrypt = DF_EncryptDirectGetL() lEncryptString$ = hex$(lEncrypt) while len(lEncryptString$) < 8 lEncryptString$ = lEncryptString$ + "#" endwhile rEncrypt as dword rEncrypt = DF_EncryptDirectGetR() rEncryptString$ = hex$(rEncrypt) while len(rEncryptString$) < 8 rEncryptString$ = rEncryptString$ + "#" endwhile encryptedByte$ = lEncryptString$ + rEncryptString$ endif ENDFUNCTION encryptedByte$ `````````````````````````````````````````````````````````````````````` ` THIS FUNCTION WILL DECRYPT A BINARY BYTE `````````````````````````````````````````````````````````````````````` FUNCTION DecryptBinaryByte(encryptedByte$) lEncrypted$ = left$(encryptedByte$,8) hashCheck = 8 isLHashed$=mid$(lEncrypted$,hashCheck) while isLHashed$ = "#" and hashCheck > 0 dec hashCheck lEncrypted$ = left$(lEncrypted$,hashCheck) isLHashed$=mid$(lEncrypted$,hashCheck) endwhile rEncrypted$ = right$(encryptedByte$,8) hashCheck = 8 isRHashed$=mid$(rEncrypted$,hashCheck) while isRHashed$ = "#" and hashCheck > 0 dec hashCheck rEncrypted$ = left$(rEncrypted$,hashCheck) isRHashed$=mid$(rEncrypted$,hashCheck) endwhile encryptedL = Hex2Dec(lEncrypted$) encryptedR = Hex2Dec(rEncrypted$) if DF_DecryptDirectSet (encryptedL,encryptedR) lDecrypt as dword lDecrypt = DF_DecryptDirectGetL() rDecrypt as dword rDecrypt = DF_DecryptDirectGetR() lString$ = str$(lDecrypt) rString$ = str$(rDecrypt) byteL$ = right$(lString$,4) byteR$ = right$(rString$,4) decryptedByte$ = byteL$ + byteR$ endif ENDFUNCTION decryptedByte$ ````````````````````````````````````````````````````````````````````````` ` THIS FUNCTION WILL ENCRYPT AN ASCI TEXT STRING ````````````````````````````````````````````````````````````````````````` FUNCTION EncryptString(aString$) sLen = len (aString$) for i = 1 to sLen l$ = mid$(aString$,i) inc i r$ = mid$(aString$,i) if r$ = "" r$ = " " endif encryptedString$ = encryptedString$ + EncryptChars(l$,r$) next i ENDFUNCTION encryptedString$ ```````````````````````````````````````````````````````````````````````` ` THIS FUNCTION WILL DECRYPT AN ENCRYPTED STRING ```````````````````````````````````````````````````````````````````````` FUNCTION DecryptString(aString$) sLen = len (aString$) for i = 1 to sLen step 16 ssLen = len (aString$) hexPair$ = right$(aString$,16) aString$ = left$(aString$,ssLen-16) decryptedString$ = DecryptChars(hexPair$) + decryptedString$ next i ENDFUNCTION decryptedString$ `````````````````````````````````````````````````````````````````````````` ` THIS FUNCTION TAKES TWO ASCI CHARACTERS AND ENCRYPTS THEM TOGETHER `````````````````````````````````````````````````````````````````````````` FUNCTION EncryptChars(charL$, charR$) asciNumL as DWORD asciNumR as DWORD randL = (rnd(8)+1) randR = (rnd(8)+1) asciNumL$ = str$(randL) + str$(asc(charL$)) asciNumR$ = str$(randR) + str$(asc(charR$)) asciNumL = val(asciNumL$) asciNumR = val(asciNumR$) if DF_EncryptDirectSet (asciNumL,asciNumR) lEncrypt as dword lEncrypt = DF_EncryptDirectGetL() lEncryptString$ = hex$(lEncrypt) while len(lEncryptString$) < 8 lEncryptString$ = lEncryptString$ + "#" endwhile rEncrypt as dword rEncrypt = DF_EncryptDirectGetR() rEncryptString$ = hex$(rEncrypt) while len(rEncryptString$) < 8 rEncryptString$ = rEncryptString$ + "#" endwhile lrEncrypted$ = lEncryptString$ + rEncryptString$ endif ENDFUNCTION lrEncrypted$ ```````````````````````````````````````````````````````````````````````````````` ` THIS FUNCTION TAKES AN ENCRYPTED PAIR AND DECTYPTS IT INTO TWO CHARACTERS ```````````````````````````````````````````````````````````````````````````````` FUNCTION DecryptChars(encryptedPair$) lEncrypted as dword rEncrypted as dword lEncrypted$=left$(encryptedPair$,8) hashCheck = 8 isLHashed$=mid$(lEncrypted$,hashCheck) while isLHashed$ = "#" and hashCheck > 0 dec hashCheck lEncrypted$ = left$(lEncrypted$,hashCheck) isLHashed$=mid$(lEncrypted$,hashCheck) endwhile rEncrypted$=right$(encryptedPair$,8) hashCheck = 8 isRHashed$=mid$(rEncrypted$,hashCheck) while isRHashed$ = "#" and hashCheck > 0 dec hashCheck rEncrypted$ = left$(rEncrypted$,hashCheck) isRHashed$=mid$(rEncrypted$,hashCheck) endwhile lEncrypted = hex2dec(lEncrypted$) rEncrypted = hex2dec(rEncrypted$) if DF_DecryptDirectSet (lEncrypted,rEncrypted) lDecrypt as dword lDecrypt$ = str$(DF_DecryptDirectGetL()) lDecrypt$ = right$(lDecrypt$,len(lDecrypt$)-1) lDecrypt = val(lDecrypt$) rDecrypt as dword rDecrypt$ = str$(DF_DecryptDirectGetR()) rDecrypt$ = right$(rDecrypt$,len(rDecrypt$)-1) rDecrypt = val(rDecrypt$) lrDecrypted$ = chr$(lDecrypt) + chr$(rDecrypt) endif ENDFUNCTION lrDecrypted$ ````````````````````````````````````````````````````````````````` ` THIS FUNCTION TURNS HEX BACK INTO LONG INTEGERS ````````````````````````````````````````````````````````````````` FUNCTION Hex2Dec(s$) p as DWORD n as DWORD d as DWORD for p = 0 to len(s$) - 1 n = asc(upper$(mid$(s$, len(s$) - p))) - 48 d = d + (n - (n > 9) * 7) * 16 ^ p next p ENDFUNCTION d