ProtectFile_XorD + UnProtectFile_XorD

Protects and unprotects a file using password
Creates another copy of the file that is protected or unprotected
You just need to call it giving it the file to protect, the destination file and password

CodeFunctionName
What is this?

Public

Tested

Original Work
' Two functions, 1 to Encrypt a file, and 1 to decrypt it
' ProtectFile_XorD to save encrypted copy of the file based on a given password
' UnProtectFile_XorD to save decrypted copy of the file using the same password used in ProtectFile_XorD
' Needs a copy of XorC function (named to XorD)
' Also IsThere2 and XorD (both provided)
' Needs ASCII_Read and ASCII_Save (not provided)
Sub ProtectFile_XorD(File2Protect, DestFile, Pwd)
' Protect, ecrypt or lock file, using Pwd as password
' Will save encrypted copy into DestFile
'
If Not IsThere2(File2Protect) Then Exit Function
If IsThere2(DestFile) Then Kill DestFile
FileB1 = ASCII_Read(File2Protect, 1)
FileB2 = XorD(FileB1, Pwd, True)
ASCII_Save DestFile, FileB2, 1
End Sub
Sub UnProtectFile_XorD(File2Unprotect, DestFile, Pwd)
' Unprotect, decrypt or unlock file that has been encrypted using ProtectFile_XorD, and same Pwd
' Will save open file to DestFile
'
If Not IsThere2(File2Unprotect) Then Exit Function
If IsThere2(DestFile) Then Kill DestFile
FileB1 = ASCII_Read(File2Unprotect, 1)
FileB2 = XorD(FileB1, Pwd, False)
ASCII_Save DestFile, FileB2, 1
End Sub

File2Protect, DestFile, Pwd
or
File2Unprotect, DestFile, Pwd

Sub Test_Encrypt()
File1 = "D:\Folder\File-Open.txt"
File2 = "D:\Folder\File-Lock.txt"
ProtectFile_XorD File2, File1, "ThyPassword"
UnProtectFile_XorD File1, File2, "ThyPassword"
End Sub

Views 1,385

Downloads 419

CodeID
DB ID