Im trying to make a light encryption program that uses my own personal version of xor so that it xors single bytes rather than integers. Im looking for a few hints on the program. First off, the professional encryption programs out there use what they call "processes" to (as i believe) create several instances of the program to run at once on the computer. This (would) have obvious speed enhancements. Is there any way to do this through blitz? If so can i get an example? Also, would the encryption go faster if I simply used a command such as "output = val(right$(input xor mask,8))"? Are there any other ways to speed my encryption? I would very much appreciate any help you pros out there could give me.
AppTitle "Xor Me!" ;create main window Global mainwin = CreateWindow("Xor Me!",GadgetWidth(Desktop()) / 3,GadgetHeight(Desktop()) / 3,350,105,0,1) CreateLabel("File: ",7,10,30,20,mainwin) Global Filebox=CreateTextField(40,10,200,20,mainwin) Global Browsebutt=CreateButton("Browse...",250,10,70,25,mainwin) Global Encbutt=CreateButton("Encrypt",10,40,70,25,mainwin) Global decbutt=CreateButton("Decrypt",95,40,70,25,mainwin) Global progbar=CreateProgBar(185,40,150,25,mainwin) ;assorted variables ;Global progbar Global splshwin Global canbutt Global fileoutloc$ Global filein Global fileout Global source Global fsize# Global bytebuff Global I# Dim buff(9) ;main window control Repeat If KeyDown(1) Then Exit WaitEvent() source = EventSource() Select EventID() Case $401 If source = browsebutt rfbuffer$ = RequestFile$() SetGadgetText(Filebox,rfbuffer$) ElseIf source = encbutt If enc%(TextFieldText$(filebox)) Notify("Succesful!") If Proceed("Delete Original File?",True) = 1 Then DeleteFile(TextFieldText$(filebox)) Else Notify("Encryption Failed!") End If ElseIf source = decbutt If dec%(TextFieldText$(filebox)) Notify("Succesful!") If Proceed("Delete Original File?",True) = 1 Then DeleteFile(TextFieldText$(filebox)) Else Notify("Decryption Failed!") End If End If Case $803 If source = mainwin Then End End Select Forever ;encryption header Function Enc%(fileinloc$) If FileType(fileinloc) <> 1 Notify "Could not open file: " + fileinloc$ Return 0 End If fsize = FileSize(fileinloc) fileoutloc$ = fileinloc + ".xor" filein = ReadFile(fileinloc) fileout = WriteFile(fileoutloc) For I = 0 To 9 buff(I) = Rand(255) WriteByte(fileout,buff(I)) Next Return main%() End Function ;decryption header Function dec%(fileinloc$) If FileType(fileinloc) <> 1 Notify "Could not open file: " + fileinloc$ Return 0 End If fsize = FileSize(fileinloc) fileoutloc$ = Left$(fileinloc,Len(fileinloc) - 4) filein = ReadFile(fileinloc) fileout = WriteFile(fileoutloc) For I = 0 To 9 buff(I) = ReadByte(filein) Next Return main%() End Function ;main loop Function main%() ;splshscr() ;start the splash screen DisableGadget(mainwin) ;disable unwanted events FlushEvents() ;ensure that the button is pressed once and only once I# = 0 ;needs to be floating point for division purposes Repeat If KeyDown(1) Then Return 0 ;possible exits of main loop If Eof(filein) Then Exit If I Mod(1000) = 0 Then UpdateProgBar(progbar,I/fsize) ;update the progbar WriteByte(fileout,bytexor(ReadByte(filein),buff(I Mod(10)))) ;calls most of the work I = I + 1 Forever EnableGadget(mainwin) FlushEvents() Return 1 End Function ;converts binary to base 10 Function val(Inputstr$) For I# = 0 To 7 integer = integer + ((2 ^ I) * Int(Right$(inputstr$,1))) inputstr$ = Left$(inputstr$,Len(inputstr) - 1) Next Return Int(integer) End Function ;Xor's and converts base 10 to binary Function bytexor(num,mask) bytestr$ = Right$(Bin$(num),8) maskstr$ = Right$(Bin$(mask),8) Local ret$ = "" For I = 0 To 7 If Left$(maskstr,1) <> Left$(bytestr,1) ret = ret + "1" Else ret = ret + "0" End If maskstr = Right$(maskstr,Len(maskstr) - 1) bytestr = Right$(bytestr,Len(bytestr) - 1) Next ret2% = val(ret) Return ret2 End Function Function main2%() DisableGadget(mainwin) ;disable unwanted events FlushEvents() ;ensure that the button is pressed once and only once I# = 0 ;needs to be floating point for division purposes Repeat If KeyDown(1) Then Return 0 ;possible exits of main loop If Eof(filein) Then Exit ; " " " " " If I Mod(1000) = 0 Then UpdateProgBar(progbar,I/fsize) ;update the progbar PokeByte(bankbuff,I,bytexor(PeekByte(bankbuff,I),buff(I Mod(10)))) ;calls most of the work I = I + 1 Forever EnableGadget(mainwin) FlushEvents() Return 1 End Function Function loadbytes() ReadBytes(bankbuff,bankfile,0,fsize) End Function Function savebytes() WriteBytes(bankbuff,fileout,0,fsize) End Function